1- import  {  NodesStatusGetter  }  from  '../../cluster/index.js' ; 
2- import  Connection  from  '../../connection/index.js' ; 
3- import  {  BatchStats ,  NodeShardStatus ,  NodeStats  }  from  '../../openapi/types.js' ; 
1+ import  {  IConnection  }  from  '../../connection/index.js' ; 
2+ import  { 
3+   BatchStats , 
4+   NodeShardStatus , 
5+   NodeStats , 
6+   NodesStatusResponse , 
7+   WeaviateReplicateRequest , 
8+   WeaviateReplicateResponse , 
9+   WeaviateReplicationResponse , 
10+   WeaviateReplicationType , 
11+   WeaviateShardingState , 
12+ }  from  '../../openapi/types.js' ; 
13+ import  {  DeepRequired  }  from  '../types/internal.js' ; 
414
515export  type  Output  =  'minimal'  |  'verbose'  |  undefined ; 
616
@@ -11,6 +21,41 @@ export type NodesOptions<O extends Output> = {
1121  output : O ; 
1222} ; 
1323
24+ export  type  QueryShardingStateOptions  =  { 
25+   /** The name of the collection to query. */ 
26+   collection : string ; 
27+   /** The name of the shard to query. If not provided, all shards will be queried. */ 
28+   shard ?: string ; 
29+ } ; 
30+ 
31+ export  type  ReplicateArguments  =  { 
32+   /** The name of the collection in which to replicate a shard. */ 
33+   collection : string ; 
34+   /** The name of the shard to replicate. */ 
35+   shard : string ; 
36+   /** The name of the node from which to replicate the shard. */ 
37+   sourceNode : string ; 
38+   /** The name of the node to which to replicate the shard. */ 
39+   targetNode : string ; 
40+   /** The type of replication to perform. */ 
41+   replicationType : WeaviateReplicationType ; 
42+ } ; 
43+ 
44+ export  type  ShardingState  =  DeepRequired < WeaviateShardingState > ; 
45+ 
46+ export  type  ReplicationOperation  =  DeepRequired < WeaviateReplicationResponse > ; 
47+ 
48+ export  type  QueryReplicationOpsOptions  =  { 
49+   /** The name of the collection to query. */ 
50+   collection ?: string ; 
51+   /** The name of the shard to query. */ 
52+   shard ?: string ; 
53+   /** The target node of the op to query. */ 
54+   targetNode ?: string ; 
55+   /** Whether to include the status history in the response. */ 
56+   includeHistory ?: boolean ; 
57+ } ; 
58+ 
1459export  type  Node < O  extends  Output >  =  { 
1560  name : string ; 
1661  status : 'HEALTHY'  |  'UNHEALTHY'  |  'UNAVAILABLE' ; 
@@ -21,14 +66,65 @@ export type Node<O extends Output> = {
2166  shards : O  extends  'minimal'  |  undefined  ? null  : Required < NodeShardStatus > [ ] ; 
2267} ; 
2368
24- const  cluster  =  ( connection : Connection )  =>  { 
69+ const  cluster  =  ( connection : IConnection )  =>  { 
2570  return  { 
26-     nodes : < O  extends  Output  =  undefined > ( opts ?: NodesOptions < O > ) : Promise < Node < O > [ ] >  =>  { 
27-       let  builder  =  new  NodesStatusGetter ( connection ) . withOutput ( opts ?. output  ? opts . output  : 'minimal' ) ; 
71+     nodes : < O  extends  Output  =  undefined > ( opts ?: NodesOptions < O > )  =>  { 
72+       const  params  =  new  URLSearchParams ( ) ; 
73+       let  path  =  '/nodes' ; 
2874      if  ( opts ?. collection )  { 
29-         builder  =  builder . withClassName ( opts . collection ) ; 
75+         path  =  path . concat ( `/ ${ opts . collection } ` ) ; 
3076      } 
31-       return  builder . do ( ) . then ( ( res )  =>  res . nodes )  as  Promise < Node < O > [ ] > ; 
77+       params . append ( 'output' ,  opts ?. output  ? opts . output  : 'minimal' ) ; 
78+       return  connection 
79+         . get < NodesStatusResponse > ( `${ path }  ?${ params . toString ( ) }  ` ) 
80+         . then ( ( res )  =>  res . nodes  as  Node < O > [ ] ) ; 
81+     } , 
82+     queryShardingState : ( opts : QueryShardingStateOptions )  =>  { 
83+       const  params  =  new  URLSearchParams ( ) ; 
84+       params . append ( 'collection' ,  opts . collection ) ; 
85+       if  ( opts . shard )  { 
86+         params . append ( 'shard' ,  opts . shard ) ; 
87+       } 
88+       return  connection 
89+         . get < ShardingState  |  undefined > ( `/replication/sharding-state?${ params . toString ( ) }  ` ) 
90+         . then ( ( res )  =>  res  as  ShardingState ) ; 
91+     } , 
92+     replicate : ( args : ReplicateArguments ) : Promise < string >  => 
93+       connection 
94+         . postReturn < WeaviateReplicateRequest ,  WeaviateReplicateResponse > ( 
95+           `/replication/replicate` , 
96+           ( ( {  replicationType,  ...rest  } )  =>  ( {  type : replicationType ,  ...rest  } ) ) ( args ) 
97+         ) 
98+         . then ( ( res )  =>  res . id ) , 
99+     replications : { 
100+       cancel : ( id : string )  =>  connection . postEmpty ( `/replication/replicate/${ id }  /cancel` ,  { } ) , 
101+       delete : ( id : string )  =>  connection . delete ( `/replication/replicate/${ id }  ` ,  { } ,  false ) , 
102+       deleteAll : ( )  =>  connection . delete ( `/replication/replicate` ,  { } ,  false ) , 
103+       get : ( id : string ,  opts ?: {  includeHistory ?: boolean  } ) : Promise < ReplicationOperation  |  null >  => 
104+         connection 
105+           . get < ReplicationOperation  |  undefined > ( 
106+             `/replication/replicate/${ id }  ?includeHistory=${  
107+               opts ?. includeHistory  ? opts ?. includeHistory  : 'false'  
108+             }  `
109+           ) 
110+           . then ( ( res )  =>  ( res  ? ( res  as  ReplicationOperation )  : null ) ) , 
111+       query : ( opts ?: QueryReplicationOpsOptions ) : Promise < ReplicationOperation [ ] >  =>  { 
112+         const  {  collection,  shard,  targetNode,  includeHistory }  =  opts  ||  { } ; 
113+         const  params  =  new  URLSearchParams ( ) ; 
114+         if  ( collection )  { 
115+           params . append ( 'collection' ,  collection ) ; 
116+         } 
117+         if  ( shard )  { 
118+           params . append ( 'shard' ,  shard ) ; 
119+         } 
120+         if  ( targetNode )  { 
121+           params . append ( 'targetNode' ,  targetNode ) ; 
122+         } 
123+         if  ( includeHistory )  { 
124+           params . append ( 'includeHistory' ,  includeHistory . toString ( ) ) ; 
125+         } 
126+         return  connection . get < ReplicationOperation [ ] > ( `/replication/replicate?${ params . toString ( ) }  ` ) ; 
127+       } , 
32128    } , 
33129  } ; 
34130} ; 
@@ -43,4 +139,60 @@ export interface Cluster {
43139   * @returns  {Promise<Node<O>[]> } The status of all nodes in the cluster. 
44140   */ 
45141  nodes : < O  extends  Output  =  undefined > ( opts ?: NodesOptions < O > )  =>  Promise < Node < O > [ ] > ; 
142+   /** 
143+    * Query the sharding state of a specific collection. 
144+    * 
145+    * @param  {QueryShardingStateOptions } opts The options for the request. 
146+    * @returns  {Promise<ShardingState> } The sharding state of the collection. 
147+    */ 
148+   queryShardingState : ( opts : QueryShardingStateOptions )  =>  Promise < ShardingState > ; 
149+   /** 
150+    * Replicate a shard from one node to another. 
151+    * 
152+    * @param  {ReplicateArguments } args The arguments for the replication request. 
153+    * @returns  {Promise<string> } The ID of the replication request. 
154+    */ 
155+   replicate : ( args : ReplicateArguments )  =>  Promise < string > ; 
156+   /** 
157+    * Access replication operations. 
158+    */ 
159+   replications : Replciations ; 
160+ } 
161+ 
162+ export  interface  Replciations  { 
163+   /** 
164+    * Cancel a replication operation. 
165+    * 
166+    * @param  {string } id The ID of the replication operation to cancel. 
167+    * @returns  {Promise<void> } A promise that resolves when the operation is cancelled. 
168+    */ 
169+   cancel : ( id : string )  =>  Promise < void > ; 
170+   /** 
171+    * Delete a replication operation. 
172+    * 
173+    * @param  {string } id The ID of the replication operation to delete. 
174+    * @returns  {Promise<void> } A promise that resolves when the operation is deleted. 
175+    */ 
176+   delete : ( id : string )  =>  Promise < void > ; 
177+   /** 
178+    * Delete all replication operations. 
179+    * 
180+    * @returns  {Promise<void> } A promise that resolves when all operations are deleted. 
181+    */ 
182+   deleteAll : ( )  =>  Promise < void > ; 
183+   /** 
184+    * Get a specific replication operation by ID. 
185+    * 
186+    * @param  {string } id The ID of the replication operation to get. 
187+    * @param  {boolean } [opts.includeHistory=false] Whether to include the status history in the response. 
188+    * @returns  {Promise<ReplicationOperation | null> } The replication operation or null if not found. 
189+    */ 
190+   get : ( id : string ,  opts ?: {  includeHistory ?: boolean  } )  =>  Promise < ReplicationOperation  |  null > ; 
191+   /** 
192+    * Query all replication operations with optional filters. 
193+    * 
194+    * @param  {QueryReplicationOpsOptions } [opts] Optional parameters for filtering the query. 
195+    * @returns  {Promise<ReplicationOperation[]> } A list of replication operations matching the query. 
196+    */ 
197+   query : ( opts ?: QueryReplicationOpsOptions )  =>  Promise < ReplicationOperation [ ] > ; 
46198} 
0 commit comments