@@ -9,22 +9,21 @@ import type {
99} from "../websocket.types.js" ;
1010
1111export async function * search (
12- pkg : string ,
12+ spec : string ,
1313 context : WebSocketContext
1414) : AsyncGenerator < WebSocketResponse , void , unknown > {
1515 const { logger, cache } = context ;
16- logger . info ( `[ws|search](pkg: ${ pkg } )` ) ;
1716
18- const cachedPayload = cache . getPayloadOrNull ( pkg ) ;
17+ const cachedPayload = cache . getPayloadOrNull ( spec ) ;
1918 if ( cachedPayload ) {
20- logger . info ( ` [ws|search](payload: ${ pkg } found in cache)` ) ;
19+ logger . info ( " [ws|command. search] one entry found in cache" ) ;
2120 const cacheList = await cache . payloadsList ( ) ;
22- if ( cacheList . mru . includes ( pkg ) ) {
23- logger . info ( ` [ws|search]( payload: ${ pkg } is already in the MRU)` ) ;
21+ if ( cacheList . mru . includes ( spec ) ) {
22+ logger . info ( " [ws|command. search] payload is already in the MRU" ) ;
2423 const updatedList : PayloadsList = {
2524 ...cacheList ,
26- current : pkg ,
27- lastUsed : { ...cacheList . lastUsed , [ pkg ] : Date . now ( ) }
25+ current : spec ,
26+ lastUsed : { ...cacheList . lastUsed , [ spec ] : Date . now ( ) }
2827 } ;
2928 await cache . updatePayloadsList ( updatedList ) ;
3029 yield {
@@ -35,7 +34,7 @@ export async function* search(
3534 if ( cache . startFromZero ) {
3635 yield {
3736 status : "RELOAD" as const ,
38- ... updatedList
37+ cache : updatedList
3938 } ;
4039 cache . startFromZero = false ;
4140 }
@@ -46,11 +45,11 @@ export async function* search(
4645 const { mru, lru, availables, lastUsed, ...updatedCache } = await cache . removeLastMRU ( ) ;
4746 const updatedList : PayloadsList = {
4847 ...updatedCache ,
49- mru : [ ...new Set ( [ ...mru , pkg ] ) ] ,
50- current : pkg ,
51- lru : lru . filter ( ( pckg ) => pckg !== pkg ) ,
52- availables : availables . filter ( ( pckg ) => pckg !== pkg ) ,
53- lastUsed : { ...lastUsed , [ pkg ] : Date . now ( ) }
48+ mru : [ ...new Set ( [ ...mru , spec ] ) ] ,
49+ current : spec ,
50+ lru : lru . filter ( ( pckg ) => pckg !== spec ) ,
51+ availables : availables . filter ( ( pckg ) => pckg !== spec ) ,
52+ lastUsed : { ...lastUsed , [ spec ] : Date . now ( ) }
5453 } ;
5554 await cache . updatePayloadsList ( updatedList ) ;
5655
@@ -60,7 +59,7 @@ export async function* search(
6059 } ;
6160 yield {
6261 status : "RELOAD" as const ,
63- ... updatedList
62+ cache : updatedList
6463 } ;
6564
6665 cache . startFromZero = false ;
@@ -69,29 +68,29 @@ export async function* search(
6968 }
7069
7170 // at this point we don't have the payload in cache so we have to scan it.
72- logger . info ( `[ws|search](scan ${ pkg } in progress)` ) ;
73- yield { status : "SCAN" as const , pkg } ;
71+ logger . info ( `[ws|command. search](scan ${ spec } in progress)` ) ;
72+ yield { status : "SCAN" as const , spec } ;
7473
75- const payload = await scanner . from ( pkg , { maxDepth : 4 } ) ;
74+ const payload = await scanner . from ( spec , { maxDepth : 4 } ) ;
7675 const name = payload . rootDependencyName ;
7776 const version = Object . keys ( payload . dependencies [ name ] . versions ) [ 0 ] ;
7877
7978 {
8079 // save the payload in cache
81- const pkg = `${ name } @${ version } ` ;
82- logger . info ( `[ws|search](scan ${ pkg } done|cache: updated)` ) ;
80+ const inScanPackageSpec = `${ name } @${ version } ` ;
81+ logger . info ( `[ws|command. search](scan ${ inScanPackageSpec } done|cache: updated)` ) ;
8382
8483 // update the payloads list
8584 const { mru, lru, availables, lastUsed, ...appCache } = await cache . removeLastMRU ( ) ;
86- mru . push ( pkg ) ;
87- cache . updatePayload ( pkg , payload ) ;
85+ mru . push ( inScanPackageSpec ) ;
86+ cache . updatePayload ( inScanPackageSpec , payload ) ;
8887 const updatedList : PayloadsList = {
8988 ...appCache ,
9089 mru : [ ...new Set ( mru ) ] ,
9190 lru,
9291 availables,
93- lastUsed : { ...lastUsed , [ pkg ] : Date . now ( ) } ,
94- current : pkg
92+ lastUsed : { ...lastUsed , [ inScanPackageSpec ] : Date . now ( ) } ,
93+ current : inScanPackageSpec
9594 } ;
9695 await cache . updatePayloadsList ( updatedList ) ;
9796
@@ -101,11 +100,11 @@ export async function* search(
101100 } ;
102101 yield {
103102 status : "RELOAD" as const ,
104- ... updatedList
103+ cache : updatedList
105104 } ;
106105
107106 cache . startFromZero = false ;
108107
109- logger . info ( "[ws|search](data sent to client|cache: updated)" ) ;
108+ logger . info ( "[ws|command. search](data sent to client|cache: updated)" ) ;
110109 }
111110}
0 commit comments