Skip to content

Commit 4b1b20e

Browse files
committed
Make changes in response to review
1 parent 882afcc commit 4b1b20e

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

src/collections/cluster/index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
WeaviateReplicationType,
1111
WeaviateShardingState,
1212
} from '../../openapi/types.js';
13-
import { DeepRequired } from '../types/internal.js';
13+
import { DeepRequired } from '../../utils/types.js';
1414

1515
export type Output = 'minimal' | 'verbose' | undefined;
1616

@@ -22,13 +22,11 @@ export type NodesOptions<O extends Output> = {
2222
};
2323

2424
export type QueryShardingStateOptions = {
25-
/** The name of the collection to query. */
26-
collection: string;
2725
/** The name of the shard to query. If not provided, all shards will be queried. */
2826
shard?: string;
2927
};
3028

31-
export type ReplicateArguments = {
29+
export type ReplicateArgs = {
3230
/** The name of the collection in which to replicate a shard. */
3331
collection: string;
3432
/** The name of the shard to replicate. */
@@ -56,6 +54,11 @@ export type QueryReplicationOpsOptions = {
5654
includeHistory?: boolean;
5755
};
5856

57+
export type GetReplicationOpOptions = {
58+
/** Whether to include the status history in the response. Defaults to false. */
59+
includeHistory?: boolean;
60+
};
61+
5962
export type Node<O extends Output> = {
6063
name: string;
6164
status: 'HEALTHY' | 'UNHEALTHY' | 'UNAVAILABLE';
@@ -79,17 +82,17 @@ const cluster = (connection: IConnection) => {
7982
.get<NodesStatusResponse>(`${path}?${params.toString()}`)
8083
.then((res) => res.nodes as Node<O>[]);
8184
},
82-
queryShardingState: (opts: QueryShardingStateOptions) => {
85+
queryShardingState: (collection: string, opts?: QueryShardingStateOptions) => {
8386
const params = new URLSearchParams();
84-
params.append('collection', opts.collection);
85-
if (opts.shard) {
87+
params.append('collection', collection);
88+
if (opts?.shard) {
8689
params.append('shard', opts.shard);
8790
}
8891
return connection
8992
.get<ShardingState | undefined>(`/replication/sharding-state?${params.toString()}`)
9093
.then((res) => res as ShardingState);
9194
},
92-
replicate: (args: ReplicateArguments): Promise<string> =>
95+
replicate: (args: ReplicateArgs): Promise<string> =>
9396
connection
9497
.postReturn<WeaviateReplicateRequest, WeaviateReplicateResponse>(
9598
`/replication/replicate`,
@@ -100,7 +103,7 @@ const cluster = (connection: IConnection) => {
100103
cancel: (id: string) => connection.postEmpty(`/replication/replicate/${id}/cancel`, {}),
101104
delete: (id: string) => connection.delete(`/replication/replicate/${id}`, {}, false),
102105
deleteAll: () => connection.delete(`/replication/replicate`, {}, false),
103-
get: (id: string, opts?: { includeHistory?: boolean }): Promise<ReplicationOperation | null> =>
106+
get: (id: string, opts?: GetReplicationOpOptions): Promise<ReplicationOperation | null> =>
104107
connection
105108
.get<ReplicationOperation | undefined>(
106109
`/replication/replicate/${id}?includeHistory=${
@@ -142,24 +145,25 @@ export interface Cluster {
142145
/**
143146
* Query the sharding state of a specific collection.
144147
*
145-
* @param {QueryShardingStateOptions} opts The options for the request.
148+
* @param {string} collection The name of the collection to query.
149+
* @param {QueryShardingStateOptions} [opts] The options for the request.
146150
* @returns {Promise<ShardingState>} The sharding state of the collection.
147151
*/
148-
queryShardingState: (opts: QueryShardingStateOptions) => Promise<ShardingState>;
152+
queryShardingState: (collection: string, opts?: QueryShardingStateOptions) => Promise<ShardingState>;
149153
/**
150154
* Replicate a shard from one node to another.
151155
*
152-
* @param {ReplicateArguments} args The arguments for the replication request.
156+
* @param {ReplicateArgs} args The arguments for the replication request.
153157
* @returns {Promise<string>} The ID of the replication request.
154158
*/
155-
replicate: (args: ReplicateArguments) => Promise<string>;
159+
replicate: (args: ReplicateArgs) => Promise<string>;
156160
/**
157161
* Access replication operations.
158162
*/
159-
replications: Replciations;
163+
replications: Replications;
160164
}
161165

162-
export interface Replciations {
166+
export interface Replications {
163167
/**
164168
* Cancel a replication operation.
165169
*

src/collections/cluster/unit.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe('Unit testing of the client.cluster methods', () => {
3333

3434
it('should query the sharding state correctly for a collection with a shard', () => {
3535
const opts = {
36-
collection: 'Collection',
3736
shard: 'shard',
3837
};
3938
const mockResult = {
@@ -46,13 +45,10 @@ describe('Unit testing of the client.cluster methods', () => {
4645
return Promise.resolve(mockResult);
4746
},
4847
};
49-
clusterMaker(mockConnection).queryShardingState(opts).then(assert(mockResult));
48+
clusterMaker(mockConnection).queryShardingState('Collection', opts).then(assert(mockResult));
5049
});
5150

5251
it('should query the sharding state correctly for a collection without a specific shard', () => {
53-
const opts = {
54-
collection: 'Collection',
55-
};
5652
const mockResult = {
5753
collection: 'Collection',
5854
shards: [
@@ -66,7 +62,7 @@ describe('Unit testing of the client.cluster methods', () => {
6662
return Promise.resolve(mockResult);
6763
},
6864
};
69-
clusterMaker(mockConnection).queryShardingState(opts).then(assert(mockResult));
65+
clusterMaker(mockConnection).queryShardingState('Collection').then(assert(mockResult));
7066
});
7167

7268
it('should replicate a shard correctly', () => {

src/collections/types/internal.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,3 @@ type AtLeastOne<T> = {
134134
}[keyof T];
135135

136136
export type NonEmpty<T> = keyof T extends never ? never : T;
137-
138-
export type DeepRequired<T> = T extends Function
139-
? T
140-
: T extends Array<infer U>
141-
? Array<DeepRequired<U>>
142-
: T extends object
143-
? { [K in keyof T]-?: DeepRequired<NonNullable<T[K]>> }
144-
: T;

src/utils/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type DeepRequired<T> = T extends Array<infer U>
2+
? Array<DeepRequired<U>>
3+
: T extends object
4+
? { [K in keyof T]-?: DeepRequired<NonNullable<T[K]>> }
5+
: T;

0 commit comments

Comments
 (0)