( route: KonnectRoute, workspaceId: string, existingByKey: Map<string, GrpcRequest>, routeCounts: SyncCounts, incomingKeys: Set<string>, )
| 141 | } |
| 142 | |
| 143 | async function syncGrpcRoute( |
| 144 | route: KonnectRoute, |
| 145 | workspaceId: string, |
| 146 | existingByKey: Map<string, GrpcRequest>, |
| 147 | routeCounts: SyncCounts, |
| 148 | incomingKeys: Set<string>, |
| 149 | ): Promise<void> { |
| 150 | const grpcProtocols = route.protocols.filter(p => p === 'grpc' || p === 'grpcs') as ('grpc' | 'grpcs')[]; |
| 151 | const multiProtocol = grpcProtocols.length > 1; |
| 152 | const paths = route.paths ?? [null]; |
| 153 | const metadata = Object.entries(route.headers ?? {}).map(([n, values]: [string, string[]]) => ({ |
| 154 | name: n.toLowerCase(), |
| 155 | value: values[0], |
| 156 | })); |
| 157 | |
| 158 | const routeFolderId = await upsertRouteFolder(workspaceId, routeDisplayName(route), route.id); |
| 159 | |
| 160 | for (const rawPath of paths) { |
| 161 | const protoMethodName = resolvePath(rawPath).path; |
| 162 | const baseName = protoMethodName || routeDisplayName(route); |
| 163 | |
| 164 | for (const protocol of grpcProtocols) { |
| 165 | let parentId = routeFolderId; |
| 166 | if (multiProtocol) { |
| 167 | const subFolderName = `${protocol.toUpperCase()} ${baseName}`; |
| 168 | parentId = await upsertFolder(routeFolderId, subFolderName, route.id); |
| 169 | } |
| 170 | |
| 171 | const pathSegment = rawPath ?? ''; |
| 172 | const key = `${route.id}:grpc:${pathSegment}:${protocol}`; |
| 173 | incomingKeys.add(key); |
| 174 | routeCounts.total++; |
| 175 | |
| 176 | const proxyHostVar = protocol === 'grpcs' ? '_.grpcs_proxy_host' : '_.grpc_proxy_host'; |
| 177 | const url = `${protocol}://{{ ${proxyHostVar} }}`; |
| 178 | const name = baseName; |
| 179 | const existing = existingByKey.get(key); |
| 180 | |
| 181 | const konnectManagedHeaderNames = metadata.map(h => h.name); |
| 182 | if (existing) { |
| 183 | const merged = mergeHeaders(existing.metadata ?? [], metadata, existing.konnectManagedHeaderNames ?? []); |
| 184 | if ( |
| 185 | existing.url !== url || |
| 186 | existing.name !== name || |
| 187 | existing.protoMethodName !== protoMethodName || |
| 188 | konnectHeadersChanged(existing.metadata ?? [], metadata, existing.konnectManagedHeaderNames ?? []) |
| 189 | ) { |
| 190 | await insoservices.grpcRequest.update(existing, { |
| 191 | url, |
| 192 | name, |
| 193 | protoMethodName, |
| 194 | metadata: merged, |
| 195 | konnectManagedHeaderNames, |
| 196 | }); |
| 197 | routeCounts.updated++; |
| 198 | } |
| 199 | } else { |
| 200 | await insoservices.grpcRequest.create({ |
no test coverage detected