Skip to content

Commit 6446dfe

Browse files
committed
refactor: name required arguments 'args' and optional 'opts'
Accept an -Opts object in the listAll() request to allow extending parameter list in the future.
1 parent 1fd81d9 commit 6446dfe

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/alias/index.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ConnectionREST } from '../index.js';
22
import { WeaviateAlias, WeaviateAliasResponse } from '../openapi/types.js';
3-
import { Alias, CreateAliasInput, UpdateAliasInput } from './types.js';
3+
import { Alias, AliasListAllOpts, CreateAliasArgs, UpdateAliasArgs } from './types.js';
44

55
export interface Aliases {
66
/**
@@ -9,19 +9,19 @@ export interface Aliases {
99
* The collection must exist prior to aliasing it.
1010
* One alias cannot be created for multiple collections simultaneously.
1111
*
12-
* @param {string} [opt.collection] Original collection name.
13-
* @param {string} [opt.alias] Alias for collection.
12+
* @param {string} args.collection Original collection name.
13+
* @param {string} args.alias Alias for collection.
1414
* @returns {Promise<void>} Awaitable promise.
1515
* */
16-
create: (opt: CreateAliasInput) => Promise<void>;
16+
create: (args: CreateAliasArgs) => Promise<void>;
1717

1818
/**
1919
* List all aliases defined in the schema.
2020
*
21-
* @param {string | undefined} collection Get all aliases defined for this collection.
21+
* @param {string | undefined} [opts.collection] Get all aliases defined for this collection.
2222
* @returns {Promise<Alias[] | undefined>} An array of aliases.
2323
*/
24-
listAll: (collection?: string) => Promise<Alias[] | undefined>;
24+
listAll: (opts?: AliasListAllOpts) => Promise<Alias[] | undefined>;
2525

2626
/**
2727
* Get information about an alias.
@@ -37,11 +37,11 @@ export interface Aliases {
3737
* To change the alias that points to the collection,
3838
* delete the alias and create a new one.
3939
*
40-
* @param {string} [opt.alias] Alias to update.
41-
* @param {string} [opt.collection] New collection the alias should point to.
40+
* @param {string} args.alias Alias to update.
41+
* @param {string} args.collection New collection the alias should point to.
4242
* @return {Promise<void>} Awaitable promise.
4343
*/
44-
update: (opt: UpdateAliasInput) => Promise<void>;
44+
update: (args: UpdateAliasArgs) => Promise<void>;
4545

4646
/**
4747
* Delete a collection alias.
@@ -54,11 +54,13 @@ export interface Aliases {
5454

5555
const alias = (connection: ConnectionREST): Aliases => {
5656
return {
57-
create: (opt: CreateAliasInput) =>
58-
connection.postReturn<WeaviateAlias, void>(`/aliases/`, { ...opt, class: opt.collection }),
59-
listAll: (collection?: string) =>
57+
create: (args: CreateAliasArgs) =>
58+
connection.postReturn<WeaviateAlias, void>(`/aliases/`, { ...args, class: args.collection }),
59+
listAll: (opts?: AliasListAllOpts) =>
6060
connection
61-
.get<WeaviateAliasResponse>(`/aliases${collection !== undefined ? '/?class=' + collection : ''}`)
61+
.get<WeaviateAliasResponse>(
62+
`/aliases${opts?.collection !== undefined ? '/?class=' + opts.collection : ''}`
63+
)
6264
.then((aliases) =>
6365
aliases.aliases !== undefined
6466
? aliases.aliases.map((alias) => ({ alias: alias.alias, collection: alias.class }))
@@ -68,8 +70,8 @@ const alias = (connection: ConnectionREST): Aliases => {
6870
connection
6971
.get<WeaviateAlias>(`/aliases/${alias}`)
7072
.then((alias) => ({ alias: alias.alias!, collection: alias.class! })),
71-
update: (opt: UpdateAliasInput) =>
72-
connection.put(`/aliases/${opt.alias}`, { class: opt.newTargetCollection }),
73+
update: (args: UpdateAliasArgs) =>
74+
connection.put(`/aliases/${args.alias}`, { class: args.newTargetCollection }),
7375
delete: (alias: string) => connection.delete(`/aliases/${alias}`, null),
7476
};
7577
};

src/alias/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ export type Alias = {
33
alias: string;
44
};
55

6-
export type CreateAliasInput = {
6+
export type CreateAliasArgs = {
77
collection: string;
88
alias: string;
99
};
1010

11-
export type UpdateAliasInput = {
11+
export type UpdateAliasArgs = {
1212
newTargetCollection: string;
1313
alias: string;
1414
};
15+
16+
export type AliasListAllOpts = {
17+
collection?: string | undefined;
18+
};

0 commit comments

Comments
 (0)