Skip to content

Commit

Permalink
feat: (APIC-190) Add manage indices endpoints (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou authored Dec 2, 2021
1 parent 202e185 commit ea1aef7
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type DeleteIndexResponse = {
/**
* TaskID of the indexing task to wait for.
*/
taskID?: number;
/**
* Date of deletion (ISO-8601 format).
*/
deleteAt?: Date;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export type Index = {
/**
* Index name.
*/
name: string;
/**
* Index creation date. An empty string means that the index has no records.
*/
createdAt: Date;
/**
* Date of last update (ISO-8601 format).
*/
updatedAt: Date;
/**
* Number of records contained in the index.
*/
entries: number;
/**
* Number of bytes of the index in minified format.
*/
dataSize: number;
/**
* Number of bytes of the index binary file.
*/
fileSize: number;
/**
* Last build time.
*/
lastBuildTimeS: number;
/**
* Number of pending indexing operations. This value is deprecated and should not be used.
*/
numberOfPendingTask?: number;
/**
* A boolean which says whether the index has pending tasks. This value is deprecated and should not be used.
*/
pendingTask: boolean;
/**
* Only present if the index is a replica. Contains the name of the related primary index.
*/
primary?: string;
/**
* Only present if the index is a primary index with replicas. Contains the names of all linked replicas.
*/
replicas?: string[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ListIndicesObject = {
/**
* Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
*/
page?: number | null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Index } from './index';

export type ListIndicesResponse = {
/**
* List of the fetched indices.
*/
items?: Index[];
/**
* Number of pages.
*/
nbPages?: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ export * from './baseSearchResponse';
export * from './baseSearchResponseFacetsStats';
export * from './batchObject';
export * from './batchResponse';
export * from './deleteIndexResponse';
export * from './errorBase';
export * from './highlightResult';
export * from './index';
export * from './indexSettings';
export * from './indexSettingsAsSearchParams';
export * from './listIndicesResponse';
export * from './multipleQueries';
export * from './multipleQueriesObject';
export * from './multipleQueriesResponse';
export * from './operation';
export * from './operationIndexObject';
export * from './operationIndexResponse';
export * from './rankingInfo';
export * from './rankingInfoMatchedGeoLocation';
export * from './record';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type OperationIndexObject = {
/**
* Type of operation to perform (move or copy).
*/
operation: OperationIndexObject.OperationEnum;
/**
* The Algolia index name.
*/
destination: string;
/**
* Scope of the data to copy. When absent, a full copy is performed. When present, only the selected scopes are copied.
*/
scope?: OperationIndexObject.ScopeEnum[];
};

export namespace OperationIndexObject {
export enum OperationEnum {
Move = 'move',
Copy = 'copy',
}
export enum ScopeEnum {
Settings = 'settings',
Synonyms = 'synonyms',
Rules = 'rules',
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type OperationIndexResponse = {
/**
* TaskID of the indexing task to wait for.
*/
taskID?: number;
/**
* Date of last update (ISO-8601 format).
*/
updatedAt?: Date;
};
106 changes: 106 additions & 0 deletions clients/algoliasearch-client-javascript/client-search/src/searchApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { BatchObject } from '../model/batchObject';
import type { BatchResponse } from '../model/batchResponse';
import type { DeleteIndexResponse } from '../model/deleteIndexResponse';
import type { IndexSettings } from '../model/indexSettings';
import type { ListIndicesResponse } from '../model/listIndicesResponse';
import { ApiKeyAuth } from '../model/models';
import type { MultipleQueriesObject } from '../model/multipleQueriesObject';
import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse';
import type { OperationIndexObject } from '../model/operationIndexObject';
import type { OperationIndexResponse } from '../model/operationIndexResponse';
import type { SaveObjectResponse } from '../model/saveObjectResponse';
import type { SearchParams } from '../model/searchParams';
import type { SearchParamsAsString } from '../model/searchParamsAsString';
Expand Down Expand Up @@ -142,6 +146,38 @@ export class SearchApi {

return this.sendRequest(request, requestOptions);
}
/**
* Delete an existing index.
*
* @summary Delete index.
* @param indexName - The index in which to perform the request.
*/
deleteIndex(indexName: string): Promise<DeleteIndexResponse> {
const path = '/1/indexes/{indexName}'.replace(
'{indexName}',
encodeURIComponent(String(indexName))
);
const headers: Headers = { Accept: 'application/json' };
const queryParameters: Record<string, string> = {};

if (indexName === null || indexName === undefined) {
throw new Error(
'Required parameter indexName was null or undefined when calling deleteIndex.'
);
}

const request: Request = {
method: 'DELETE',
path,
};

const requestOptions: RequestOptions = {
headers,
queryParameters,
};

return this.sendRequest(request, requestOptions);
}
/**
* Retrieve settings of a given indexName.
*
Expand Down Expand Up @@ -173,6 +209,33 @@ export class SearchApi {

return this.sendRequest(request, requestOptions);
}
/**
* List existing indexes from an application.
*
* @summary List existing indexes.
* @param page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
*/
listIndices(page?: number): Promise<ListIndicesResponse> {
const path = '/1/indexes';
const headers: Headers = { Accept: 'application/json' };
const queryParameters: Record<string, string> = {};

if (page !== undefined) {
queryParameters.Page = page.toString();
}

const request: Request = {
method: 'GET',
path,
};

const requestOptions: RequestOptions = {
headers,
queryParameters,
};

return this.sendRequest(request, requestOptions);
}
/**
* Get search results for the given requests.
*
Expand Down Expand Up @@ -204,6 +267,49 @@ export class SearchApi {

return this.sendRequest(request, requestOptions);
}
/**
* Peforms a copy or a move operation on a index.
*
* @summary Copy/move index.
* @param indexName - The index in which to perform the request.
* @param operationIndexObject - The operationIndexObject.
*/
operationIndex(
indexName: string,
operationIndexObject: OperationIndexObject
): Promise<OperationIndexResponse> {
const path = '/1/indexes/{indexName}/operation'.replace(
'{indexName}',
encodeURIComponent(String(indexName))
);
const headers: Headers = { Accept: 'application/json' };
const queryParameters: Record<string, string> = {};

if (indexName === null || indexName === undefined) {
throw new Error(
'Required parameter indexName was null or undefined when calling operationIndex.'
);
}

if (operationIndexObject === null || operationIndexObject === undefined) {
throw new Error(
'Required parameter operationIndexObject was null or undefined when calling operationIndex.'
);
}

const request: Request = {
method: 'POST',
path,
data: operationIndexObject,
};

const requestOptions: RequestOptions = {
headers,
queryParameters,
};

return this.sendRequest(request, requestOptions);
}
/**
* Add an object to the index, automatically assigning it an object ID.
*
Expand Down
15 changes: 15 additions & 0 deletions specs/common/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ ForwardToReplicas:
schema:
type: boolean

# query
Page:
in: query
name: Page
description: Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
schema:
type: integer
nullable: true
default: null

# misc
taskID:
type: integer
Expand Down Expand Up @@ -49,6 +59,11 @@ updatedAt:
format: date-time
description: Date of last update (ISO-8601 format).

deleteAt:
type: string
format: date-time
description: Date of deletion (ISO-8601 format).

indexName:
type: string
example: products
Expand Down
62 changes: 62 additions & 0 deletions specs/search/common/schemas/listIndicesResponse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
listIndicesResponse:
type: object
additionalProperties: false
properties:
items:
type: array
description: List of the fetched indices.
items:
$ref: '#/index'
nbPages:
type: integer
description: Number of pages.
example: 100

index:
type: object
additionalProperties: false
properties:
name:
type: string
description: Index name.
createdAt:
type: string
format: date-time
description: Index creation date. An empty string means that the index has no records.
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
entries:
type: integer
description: Number of records contained in the index.
dataSize:
type: integer
description: Number of bytes of the index in minified format.
fileSize:
type: integer
description: Number of bytes of the index binary file.
lastBuildTimeS:
type: integer
description: Last build time
numberOfPendingTask:
type: integer
description: Number of pending indexing operations. This value is deprecated and should not be used.
pendingTask:
type: boolean
description: A boolean which says whether the index has pending tasks. This value is deprecated and should not be used.
primary:
type: string
description: Only present if the index is a replica. Contains the name of the related primary index.
replicas:
type: array
items:
type: string
description: Only present if the index is a primary index with replicas. Contains the names of all linked replicas.
required:
- name
- createdAt
- updatedAt
- entries
- dataSize
- fileSize
- lastBuildTimeS
- pendingTask
1 change: 0 additions & 1 deletion specs/search/paths/manage_indices/copyIndex.yml

This file was deleted.

22 changes: 22 additions & 0 deletions specs/search/paths/manage_indices/listIndices.yml
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
get:
tags:
- search
operationId: listIndices
summary: List existing indexes.
description: List existing indexes from an application.
parameters:
- $ref: '../../../common/parameters.yml#/Page'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '../../common/schemas/listIndicesResponse.yml#/listIndicesResponse'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
$ref: '../../../common/responses/FeatureNotEnabled.yml'
'403':
$ref: '../../../common/responses/MethodNotAllowed.yml'
'404':
$ref: '../../../common/responses/IndexNotFound.yml'
Loading

0 comments on commit ea1aef7

Please sign in to comment.