99import {
1010 captureNodePairingGeneration ,
1111 isNodePairingGenerationCurrent ,
12- type NodePairingGeneration ,
1312} from "../../infra/device-pairing-node-state.js" ;
1413import {
1514 drainNodePendingWork ,
@@ -20,12 +19,12 @@ import {
2019} from "../node-pending-work.js" ;
2120import {
2221 captureNodeWakeLifecycle ,
23- isNodeWakeLifecycleCurrent ,
2422 NODE_WAKE_RECONNECT_RETRY_WAIT_MS ,
2523 NODE_WAKE_RECONNECT_WAIT_MS ,
2624 releaseNodeWakeLifecycle ,
2725} from "../node-wake-state.js" ;
2826import { respondUnavailableOnThrow } from "./nodes.helpers.js" ;
27+ import { isNodePairingWorkCurrent } from "./nodes.shared.js" ;
2928import {
3029 maybeSendNodeWakeNudge ,
3130 maybeWakeNodeWithApns ,
@@ -46,17 +45,6 @@ function respondPairingChanged(respond: RespondFn) {
4645 ) ;
4746}
4847
49- async function isPendingGenerationCurrent ( params : {
50- nodeId : string ;
51- generation : NodePairingGeneration ;
52- lifecycle : AbortSignal ;
53- } ) : Promise < boolean > {
54- return (
55- isNodeWakeLifecycleCurrent ( params . nodeId , params . lifecycle , params . generation . key ) &&
56- ( await isNodePairingGenerationCurrent ( params . generation ) )
57- ) ;
58- }
59-
6048function resolveClientNodeId (
6149 client : { connect ?: { device ?: { id ?: string } ; client ?: { id ?: string } } } | null ,
6250) : string | null {
@@ -127,7 +115,7 @@ export const nodePendingWorkHandlers: GatewayRequestHandlers = {
127115 }
128116 const wakeLifecycle = captureNodeWakeLifecycle ( nodeId , generation . key ) ;
129117 try {
130- if ( ! ( await isPendingGenerationCurrent ( { nodeId, generation, lifecycle : wakeLifecycle } ) ) ) {
118+ if ( ! ( await isNodePairingWorkCurrent ( { nodeId, generation, lifecycle : wakeLifecycle } ) ) ) {
131119 respondPairingChanged ( respond ) ;
132120 return ;
133121 }
@@ -178,7 +166,7 @@ export const nodePendingWorkHandlers: GatewayRequestHandlers = {
178166 ) ;
179167 }
180168 if (
181- ( await isPendingGenerationCurrent ( {
169+ ( await isNodePairingWorkCurrent ( {
182170 nodeId,
183171 generation,
184172 lifecycle : wakeLifecycle ,
@@ -216,7 +204,7 @@ export const nodePendingWorkHandlers: GatewayRequestHandlers = {
216204 }
217205 }
218206 if (
219- ( await isPendingGenerationCurrent ( {
207+ ( await isNodePairingWorkCurrent ( {
220208 nodeId,
221209 generation,
222210 lifecycle : wakeLifecycle ,
@@ -237,7 +225,7 @@ export const nodePendingWorkHandlers: GatewayRequestHandlers = {
237225 `node pending wake done node=${ nodeId } req=${ wakeReqId } connected=false reason=not_connected` ,
238226 ) ;
239227 } else if (
240- await isPendingGenerationCurrent ( {
228+ await isNodePairingWorkCurrent ( {
241229 nodeId,
242230 generation,
243231 lifecycle : wakeLifecycle ,
@@ -248,7 +236,7 @@ export const nodePendingWorkHandlers: GatewayRequestHandlers = {
248236 ) ;
249237 }
250238 }
251- if ( ! ( await isPendingGenerationCurrent ( { nodeId, generation, lifecycle : wakeLifecycle } ) ) ) {
239+ if ( ! ( await isNodePairingWorkCurrent ( { nodeId, generation, lifecycle : wakeLifecycle } ) ) ) {
252240 if ( ! queued . deduped ) {
253241 removeNodePendingWorkItem ( {
254242 nodeId,
0 commit comments