11import { status } from '@grpc/grpc-js' ;
22import { filterNullAndUndefined } from '@temporalio/common/lib/internal-non-workflow' ;
33import { assertNever , SymbolBasedInstanceOfError , RequireAtLeastOne } from '@temporalio/common/lib/type-helpers' ;
4+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow' ;
45import { temporal } from '@temporalio/proto' ;
56import { BaseClient , BaseClientOptions , defaultBaseClientOptions , LoadedWithDefaults } from './base-client' ;
67import { WorkflowService } from './types' ;
@@ -148,7 +149,7 @@ export class TaskQueueClient extends BaseClient {
148149 namespace : this . options . namespace ,
149150 taskQueues : options . taskQueues ,
150151 buildIds,
151- reachability : reachabilityTypeToProto ( options . reachability ) ,
152+ reachability : encodeTaskReachability ( options . reachability ) ,
152153 } ) ;
153154 } catch ( e ) {
154155 this . rethrowGrpcError ( e , 'Unexpected error fetching Build Id reachability' ) ;
@@ -173,14 +174,45 @@ export class TaskQueueClient extends BaseClient {
173174 */
174175export type ReachabilityOptions = RequireAtLeastOne < BaseReachabilityOptions , 'buildIds' | 'taskQueues' > ;
175176
177+ export const ReachabilityType = {
178+ /** The Build Id might be used by new workflows. */
179+ NEW_WORKFLOWS : 'NEW_WORKFLOWS' ,
180+
181+ /** The Build Id might be used by open workflows and/or closed workflows. */
182+ EXISTING_WORKFLOWS : 'EXISTING_WORKFLOWS' ,
183+
184+ /** The Build Id might be used by open workflows. */
185+ OPEN_WORKFLOWS : 'OPEN_WORKFLOWS' ,
186+
187+ /** The Build Id might be used by closed workflows. */
188+ CLOSED_WORKFLOWS : 'CLOSED_WORKFLOWS' ,
189+ } as const ;
190+
176191/**
177192 * There are different types of reachability:
178193 * - `NEW_WORKFLOWS`: The Build Id might be used by new workflows
179194 * - `EXISTING_WORKFLOWS` The Build Id might be used by open workflows and/or closed workflows.
180195 * - `OPEN_WORKFLOWS` The Build Id might be used by open workflows
181196 * - `CLOSED_WORKFLOWS` The Build Id might be used by closed workflows
182197 */
183- export type ReachabilityType = 'NEW_WORKFLOWS' | 'EXISTING_WORKFLOWS' | 'OPEN_WORKFLOWS' | 'CLOSED_WORKFLOWS' ;
198+ export type ReachabilityType = ( typeof ReachabilityType ) [ keyof typeof ReachabilityType ] ;
199+
200+ export const [ encodeTaskReachability , decodeTaskReachability ] = makeProtoEnumConverters <
201+ temporal . api . enums . v1 . TaskReachability ,
202+ typeof temporal . api . enums . v1 . TaskReachability ,
203+ keyof typeof temporal . api . enums . v1 . TaskReachability ,
204+ typeof ReachabilityType ,
205+ 'TASK_REACHABILITY_'
206+ > (
207+ {
208+ [ ReachabilityType . NEW_WORKFLOWS ] : 1 ,
209+ [ ReachabilityType . EXISTING_WORKFLOWS ] : 2 ,
210+ [ ReachabilityType . OPEN_WORKFLOWS ] : 3 ,
211+ [ ReachabilityType . CLOSED_WORKFLOWS ] : 4 ,
212+ UNSPECIFIED : 0 ,
213+ } as const ,
214+ 'TASK_REACHABILITY_'
215+ ) ;
184216
185217/**
186218 * See {@link ReachabilityOptions}
@@ -215,24 +247,6 @@ export interface BuildIdReachability {
215247 taskQueueReachability : Record < string , ReachabilityTypeResponse [ ] > ;
216248}
217249
218- function reachabilityTypeToProto ( type : ReachabilityType | undefined | null ) : temporal . api . enums . v1 . TaskReachability {
219- switch ( type ) {
220- case null :
221- case undefined :
222- return temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_UNSPECIFIED ;
223- case 'NEW_WORKFLOWS' :
224- return temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_NEW_WORKFLOWS ;
225- case 'EXISTING_WORKFLOWS' :
226- return temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_EXISTING_WORKFLOWS ;
227- case 'OPEN_WORKFLOWS' :
228- return temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_OPEN_WORKFLOWS ;
229- case 'CLOSED_WORKFLOWS' :
230- return temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_CLOSED_WORKFLOWS ;
231- default :
232- assertNever ( 'Unknown Build Id reachability operation' , type ) ;
233- }
234- }
235-
236250export function reachabilityResponseFromProto ( resp : GetWorkerTaskReachabilityResponse ) : ReachabilityResponse {
237251 return {
238252 buildIdReachability : Object . fromEntries (
@@ -247,7 +261,9 @@ export function reachabilityResponseFromProto(resp: GetWorkerTaskReachabilityRes
247261 taskQueueReachability [ tqr . taskQueue ] = [ ] ;
248262 continue ;
249263 }
250- taskQueueReachability [ tqr . taskQueue ] = tqr . reachability . map ( reachabilityTypeFromProto ) ;
264+ taskQueueReachability [ tqr . taskQueue ] = tqr . reachability . map (
265+ ( x ) => decodeTaskReachability ( x ) ?? 'NOT_FETCHED'
266+ ) ;
251267 }
252268 }
253269 let bid : string | UnversionedBuildIdType ;
@@ -262,23 +278,6 @@ export function reachabilityResponseFromProto(resp: GetWorkerTaskReachabilityRes
262278 } ;
263279}
264280
265- function reachabilityTypeFromProto ( rtype : temporal . api . enums . v1 . TaskReachability ) : ReachabilityTypeResponse {
266- switch ( rtype ) {
267- case temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_UNSPECIFIED :
268- return 'NOT_FETCHED' ;
269- case temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_NEW_WORKFLOWS :
270- return 'NEW_WORKFLOWS' ;
271- case temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_EXISTING_WORKFLOWS :
272- return 'EXISTING_WORKFLOWS' ;
273- case temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_OPEN_WORKFLOWS :
274- return 'OPEN_WORKFLOWS' ;
275- case temporal . api . enums . v1 . TaskReachability . TASK_REACHABILITY_CLOSED_WORKFLOWS :
276- return 'CLOSED_WORKFLOWS' ;
277- default :
278- return assertNever ( 'Unknown Build Id reachability operation' , rtype ) ;
279- }
280- }
281-
282281/**
283282 * Thrown when one or more Build Ids are not found while using the {@link TaskQueueClient}.
284283 *
0 commit comments