diff --git a/sdk/search/perf-tests/search-documents/package.json b/sdk/search/perf-tests/search-documents/package.json index ada023755ef6..7d6f903832b5 100644 --- a/sdk/search/perf-tests/search-documents/package.json +++ b/sdk/search/perf-tests/search-documents/package.json @@ -9,7 +9,7 @@ "license": "ISC", "dependencies": { "@azure/identity": "^2.0.1", - "@azure/search-documents": "11.3.0-beta.6", + "@azure/search-documents": "11.3.0-beta.7", "@azure/test-utils-perf": "^1.0.0", "dotenv": "^8.2.0" }, diff --git a/sdk/search/search-documents/CHANGELOG.md b/sdk/search/search-documents/CHANGELOG.md index 2154e97f1065..87f9dd2aa5f5 100644 --- a/sdk/search/search-documents/CHANGELOG.md +++ b/sdk/search/search-documents/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 11.3.0-beta.7 (2022-03-08) + +### Features Added + +- Added new APIs `createAlias`, `createOrUpdateAlias`, `deleteAlias`, `getAlias` & `listAliases` operations to the `SearchIndexClient`. + ## 11.3.0-beta.6 (2022-02-08) ### Features Added diff --git a/sdk/search/search-documents/package.json b/sdk/search/search-documents/package.json index 05aa48aee32c..62a2b4ff4831 100644 --- a/sdk/search/search-documents/package.json +++ b/sdk/search/search-documents/package.json @@ -1,6 +1,6 @@ { "name": "@azure/search-documents", - "version": "11.3.0-beta.6", + "version": "11.3.0-beta.7", "description": "Azure client library to use Cognitive Search for node.js and browser.", "sdk-type": "client", "main": "dist/index.js", diff --git a/sdk/search/search-documents/review/search-documents.api.md b/sdk/search/search-documents/review/search-documents.api.md index 836864632b5f..954d43588e81 100644 --- a/sdk/search/search-documents/review/search-documents.api.md +++ b/sdk/search/search-documents/review/search-documents.api.md @@ -14,6 +14,9 @@ import { PagedAsyncIterableIterator } from '@azure/core-paging'; import { RestError } from '@azure/core-rest-pipeline'; import { TokenCredential } from '@azure/core-auth'; +// @public +export type AliasIterator = PagedAsyncIterableIterator; + // @public export interface AnalyzedTokenInfo { readonly endOffset: number; @@ -273,6 +276,9 @@ export interface CorsOptions { // @public export type CountDocumentsOptions = OperationOptions; +// @public +export type CreateAliasOptions = OperationOptions; + // @public export type CreateDataSourceConnectionOptions = OperationOptions; @@ -282,6 +288,11 @@ export type CreateIndexerOptions = OperationOptions; // @public export type CreateIndexOptions = OperationOptions; +// @public +export interface CreateOrUpdateAliasOptions extends OperationOptions { + onlyIfUnchanged?: boolean; +} + // @public export interface CreateorUpdateDataSourceConnectionOptions extends OperationOptions { onlyIfUnchanged?: boolean; @@ -396,6 +407,11 @@ export type DefaultCognitiveServicesAccount = BaseCognitiveServicesAccount & { odatatype: "#Microsoft.Azure.Search.DefaultCognitiveServices"; }; +// @public +export interface DeleteAliasOptions extends OperationOptions { + onlyIfUnchanged?: boolean; +} + // @public export interface DeleteDataSourceConnectionOptions extends OperationOptions { onlyIfUnchanged?: boolean; @@ -557,6 +573,9 @@ export class GeographyPoint { toJSON(): Record; } +// @public +export type GetAliasOptions = OperationOptions; + // @public export type GetDataSourceConnectionOptions = OperationOptions; @@ -1541,6 +1560,9 @@ export type LimitTokenFilter = BaseTokenFilter & { // @public export type LineEnding = string; +// @public +export type ListAliasesOptions = OperationOptions; + // @public export type ListDataSourceConnectionsOptions = OperationOptions; @@ -1809,6 +1831,13 @@ export interface ScoringProfile { // @public export type ScoringStatistics = "local" | "global"; +// @public +export interface SearchAlias { + etag?: string; + indexes: string[]; + name: string; +} + // @public export class SearchClient implements IndexDocumentsClient { constructor(endpoint: string, indexName: string, credential: KeyCredential | TokenCredential, options?: SearchClientOptions); @@ -1883,24 +1912,32 @@ export interface SearchIndex { tokenizers?: LexicalTokenizer[]; } +// @public +export type SearchIndexAlias = SearchAlias; + // @public export class SearchIndexClient { constructor(endpoint: string, credential: KeyCredential | TokenCredential, options?: SearchIndexClientOptions); analyzeText(indexName: string, options: AnalyzeTextOptions): Promise; // @deprecated readonly apiVersion: string; + createAlias(alias: SearchIndexAlias, options?: CreateAliasOptions): Promise; createIndex(index: SearchIndex, options?: CreateIndexOptions): Promise; + createOrUpdateAlias(alias: SearchIndexAlias, options?: CreateOrUpdateAliasOptions): Promise; createOrUpdateIndex(index: SearchIndex, options?: CreateOrUpdateIndexOptions): Promise; createOrUpdateSynonymMap(synonymMap: SynonymMap, options?: CreateOrUpdateSynonymMapOptions): Promise; createSynonymMap(synonymMap: SynonymMap, options?: CreateSynonymMapOptions): Promise; + deleteAlias(alias: string | SearchIndexAlias, options?: DeleteAliasOptions): Promise; deleteIndex(index: string | SearchIndex, options?: DeleteIndexOptions): Promise; deleteSynonymMap(synonymMap: string | SynonymMap, options?: DeleteSynonymMapOptions): Promise; readonly endpoint: string; + getAlias(aliasName: string, options?: GetAliasOptions): Promise; getIndex(indexName: string, options?: GetIndexOptions): Promise; getIndexStatistics(indexName: string, options?: GetIndexStatisticsOptions): Promise; getSearchClient(indexName: string, options?: SearchClientOptions): SearchClient; getServiceStatistics(options?: GetServiceStatisticsOptions): Promise; getSynonymMap(synonymMapName: string, options?: GetSynonymMapsOptions): Promise; + listAliases(options?: ListAliasesOptions): AliasIterator; listIndexes(options?: ListIndexesOptions): IndexIterator; listIndexesNames(options?: ListIndexesOptions): IndexNameIterator; listSynonymMaps(options?: ListSynonymMapsOptions): Promise>; @@ -2291,6 +2328,7 @@ export type SentimentSkillV3 = BaseSearchIndexerSkill & { // @public export interface ServiceCounters { + aliasCounter?: ResourceCounter; dataSourceCounter: ResourceCounter; documentCounter: ResourceCounter; indexCounter: ResourceCounter; diff --git a/sdk/search/search-documents/src/constants.ts b/sdk/search/search-documents/src/constants.ts index 223048a7ed90..2a3373482dbe 100644 --- a/sdk/search/search-documents/src/constants.ts +++ b/sdk/search/search-documents/src/constants.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -export const SDK_VERSION: string = "11.3.0-beta.6"; +export const SDK_VERSION: string = "11.3.0-beta.7"; diff --git a/sdk/search/search-documents/src/generated/data/searchClientContext.ts b/sdk/search/search-documents/src/generated/data/searchClientContext.ts index ff990504a805..7e8b71912862 100644 --- a/sdk/search/search-documents/src/generated/data/searchClientContext.ts +++ b/sdk/search/search-documents/src/generated/data/searchClientContext.ts @@ -49,7 +49,7 @@ export class SearchClientContext extends coreClient.ServiceClient { requestContentType: "application/json; charset=utf-8" }; - const packageDetails = `azsdk-js-search-documents/11.3.0-beta.6`; + const packageDetails = `azsdk-js-search-documents/11.3.0-beta.7`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` diff --git a/sdk/search/search-documents/src/generated/service/models/index.ts b/sdk/search/search-documents/src/generated/service/models/index.ts index efb962d34d6e..ea004a4b8a45 100644 --- a/sdk/search/search-documents/src/generated/service/models/index.ts +++ b/sdk/search/search-documents/src/generated/service/models/index.ts @@ -5,6 +5,7 @@ * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ + import * as coreClient from "@azure/core-client"; export type SearchIndexerDataIdentityUnion = @@ -1005,6 +1006,25 @@ export interface AnalyzedTokenInfo { readonly position: number; } +/** Represents an index alias, which describes a mapping from the alias name to an index. The alias name can be used in place of the index name for supported operations. */ +export interface SearchAlias { + /** The name of the alias. */ + name: string; + /** The name of the index this alias maps to. Only one index name may be specified. */ + indexes: string[]; + /** The ETag of the alias. */ + etag?: string; +} + +/** Response from a List Aliases request. If successful, it includes the associated index mappings for all aliases. */ +export interface ListAliasesResult { + /** + * The aliases in the Search service. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly aliases: SearchAlias[]; +} + /** Response from a get service statistics request. If successful, it includes service level counters and limits. */ export interface ServiceStatistics { /** Service level resource counters. */ @@ -1015,6 +1035,8 @@ export interface ServiceStatistics { /** Represents service-level resource counters and quotas. */ export interface ServiceCounters { + /** Total number of aliases. */ + aliasCounter?: ResourceCounter; /** Total number of documents across all indexes in the service. */ documentCounter: ResourceCounter; /** Total number of indexes. */ @@ -4104,6 +4126,59 @@ export interface IndexesAnalyzeOptionalParams /** Contains response data for the analyze operation. */ export type IndexesAnalyzeResponse = AnalyzeResult; +/** Optional parameters. */ +export interface AliasesCreateOptionalParams + extends coreClient.OperationOptions { + /** Parameter group */ + requestOptionsParam?: RequestOptions; +} + +/** Contains response data for the create operation. */ +export type AliasesCreateResponse = SearchAlias; + +/** Optional parameters. */ +export interface AliasesListOptionalParams extends coreClient.OperationOptions { + /** Parameter group */ + requestOptionsParam?: RequestOptions; +} + +/** Contains response data for the list operation. */ +export type AliasesListResponse = ListAliasesResult; + +/** Optional parameters. */ +export interface AliasesCreateOrUpdateOptionalParams + extends coreClient.OperationOptions { + /** Parameter group */ + requestOptionsParam?: RequestOptions; + /** Defines the If-Match condition. The operation will be performed only if the ETag on the server matches this value. */ + ifMatch?: string; + /** Defines the If-None-Match condition. The operation will be performed only if the ETag on the server does not match this value. */ + ifNoneMatch?: string; +} + +/** Contains response data for the createOrUpdate operation. */ +export type AliasesCreateOrUpdateResponse = SearchAlias; + +/** Optional parameters. */ +export interface AliasesDeleteOptionalParams + extends coreClient.OperationOptions { + /** Parameter group */ + requestOptionsParam?: RequestOptions; + /** Defines the If-Match condition. The operation will be performed only if the ETag on the server matches this value. */ + ifMatch?: string; + /** Defines the If-None-Match condition. The operation will be performed only if the ETag on the server does not match this value. */ + ifNoneMatch?: string; +} + +/** Optional parameters. */ +export interface AliasesGetOptionalParams extends coreClient.OperationOptions { + /** Parameter group */ + requestOptionsParam?: RequestOptions; +} + +/** Contains response data for the get operation. */ +export type AliasesGetResponse = SearchAlias; + /** Optional parameters. */ export interface SearchServiceClientGetServiceStatisticsOptionalParams extends coreClient.OperationOptions { diff --git a/sdk/search/search-documents/src/generated/service/models/mappers.ts b/sdk/search/search-documents/src/generated/service/models/mappers.ts index 12e05cb558b9..4a1278291fdd 100644 --- a/sdk/search/search-documents/src/generated/service/models/mappers.ts +++ b/sdk/search/search-documents/src/generated/service/models/mappers.ts @@ -2390,6 +2390,63 @@ export const AnalyzedTokenInfo: coreClient.CompositeMapper = { } }; +export const SearchAlias: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "SearchAlias", + modelProperties: { + name: { + serializedName: "name", + required: true, + type: { + name: "String" + } + }, + indexes: { + serializedName: "indexes", + required: true, + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + etag: { + serializedName: "@odata\\.etag", + type: { + name: "String" + } + } + } + } +}; + +export const ListAliasesResult: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "ListAliasesResult", + modelProperties: { + aliases: { + serializedName: "value", + required: true, + readOnly: true, + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "SearchAlias" + } + } + } + } + } + } +}; + export const ServiceStatistics: coreClient.CompositeMapper = { type: { name: "Composite", @@ -2418,6 +2475,13 @@ export const ServiceCounters: coreClient.CompositeMapper = { name: "Composite", className: "ServiceCounters", modelProperties: { + aliasCounter: { + serializedName: "aliasesCount", + type: { + name: "Composite", + className: "ResourceCounter" + } + }, documentCounter: { serializedName: "documentCount", type: { diff --git a/sdk/search/search-documents/src/generated/service/models/parameters.ts b/sdk/search/search-documents/src/generated/service/models/parameters.ts index 48dccbf93a59..81eaec7cc22b 100644 --- a/sdk/search/search-documents/src/generated/service/models/parameters.ts +++ b/sdk/search/search-documents/src/generated/service/models/parameters.ts @@ -19,7 +19,8 @@ import { SkillNames as SkillNamesMapper, SynonymMap as SynonymMapMapper, SearchIndex as SearchIndexMapper, - AnalyzeRequest as AnalyzeRequestMapper + AnalyzeRequest as AnalyzeRequestMapper, + SearchAlias as SearchAliasMapper } from "../models/mappers"; export const contentType: OperationParameter = { @@ -256,3 +257,19 @@ export const request: OperationParameter = { parameterPath: "request", mapper: AnalyzeRequestMapper }; + +export const alias: OperationParameter = { + parameterPath: "alias", + mapper: SearchAliasMapper +}; + +export const aliasName: OperationURLParameter = { + parameterPath: "aliasName", + mapper: { + serializedName: "aliasName", + required: true, + type: { + name: "String" + } + } +}; diff --git a/sdk/search/search-documents/src/generated/service/operations/aliases.ts b/sdk/search/search-documents/src/generated/service/operations/aliases.ts new file mode 100644 index 000000000000..e375dfe8961a --- /dev/null +++ b/sdk/search/search-documents/src/generated/service/operations/aliases.ts @@ -0,0 +1,214 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { Aliases } from "../operationsInterfaces"; +import * as coreClient from "@azure/core-client"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { SearchServiceClientContext } from "../searchServiceClientContext"; +import { + SearchAlias, + AliasesCreateOptionalParams, + AliasesCreateResponse, + AliasesListOptionalParams, + AliasesListResponse, + AliasesCreateOrUpdateOptionalParams, + AliasesCreateOrUpdateResponse, + AliasesDeleteOptionalParams, + AliasesGetOptionalParams, + AliasesGetResponse +} from "../models"; + +/** Class containing Aliases operations. */ +export class AliasesImpl implements Aliases { + private readonly client: SearchServiceClientContext; + + /** + * Initialize a new instance of the class Aliases class. + * @param client Reference to the service client + */ + constructor(client: SearchServiceClientContext) { + this.client = client; + } + + /** + * Creates a new search alias. + * @param alias The definition of the alias to create. + * @param options The options parameters. + */ + create( + alias: SearchAlias, + options?: AliasesCreateOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { alias, options }, + createOperationSpec + ); + } + + /** + * Lists all aliases available for a search service. + * @param options The options parameters. + */ + list(options?: AliasesListOptionalParams): Promise { + return this.client.sendOperationRequest({ options }, listOperationSpec); + } + + /** + * Creates a new search alias or updates an alias if it already exists. + * @param aliasName The definition of the alias to create or update. + * @param alias The definition of the alias to create or update. + * @param options The options parameters. + */ + createOrUpdate( + aliasName: string, + alias: SearchAlias, + options?: AliasesCreateOrUpdateOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { aliasName, alias, options }, + createOrUpdateOperationSpec + ); + } + + /** + * Deletes a search alias and its associated mapping to an index. This operation is permanent, with no + * recovery option. The mapped index is untouched by this operation. + * @param aliasName The name of the alias to delete. + * @param options The options parameters. + */ + delete( + aliasName: string, + options?: AliasesDeleteOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { aliasName, options }, + deleteOperationSpec + ); + } + + /** + * Retrieves an alias definition. + * @param aliasName The name of the alias to retrieve. + * @param options The options parameters. + */ + get( + aliasName: string, + options?: AliasesGetOptionalParams + ): Promise { + return this.client.sendOperationRequest( + { aliasName, options }, + getOperationSpec + ); + } +} +// Operation Specifications +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); + +const createOperationSpec: coreClient.OperationSpec = { + path: "/aliases", + httpMethod: "POST", + responses: { + 201: { + bodyMapper: Mappers.SearchAlias + }, + default: { + bodyMapper: Mappers.SearchError + } + }, + requestBody: Parameters.alias, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint], + headerParameters: [ + Parameters.contentType, + Parameters.accept, + Parameters.xMsClientRequestId + ], + mediaType: "json", + serializer +}; +const listOperationSpec: coreClient.OperationSpec = { + path: "/aliases", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.ListAliasesResult + }, + default: { + bodyMapper: Mappers.SearchError + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint], + headerParameters: [Parameters.accept, Parameters.xMsClientRequestId], + serializer +}; +const createOrUpdateOperationSpec: coreClient.OperationSpec = { + path: "/aliases('{aliasName}')", + httpMethod: "PUT", + responses: { + 200: { + bodyMapper: Mappers.SearchAlias + }, + 201: { + bodyMapper: Mappers.SearchAlias + }, + default: { + bodyMapper: Mappers.SearchError + } + }, + requestBody: Parameters.alias, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.aliasName], + headerParameters: [ + Parameters.contentType, + Parameters.accept, + Parameters.xMsClientRequestId, + Parameters.ifMatch, + Parameters.ifNoneMatch, + Parameters.prefer + ], + mediaType: "json", + serializer +}; +const deleteOperationSpec: coreClient.OperationSpec = { + path: "/aliases('{aliasName}')", + httpMethod: "DELETE", + responses: { + 204: {}, + 404: {}, + default: { + bodyMapper: Mappers.SearchError + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.aliasName], + headerParameters: [ + Parameters.accept, + Parameters.xMsClientRequestId, + Parameters.ifMatch, + Parameters.ifNoneMatch + ], + serializer +}; +const getOperationSpec: coreClient.OperationSpec = { + path: "/aliases('{aliasName}')", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.SearchAlias + }, + default: { + bodyMapper: Mappers.SearchError + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.aliasName], + headerParameters: [Parameters.accept, Parameters.xMsClientRequestId], + serializer +}; diff --git a/sdk/search/search-documents/src/generated/service/operations/index.ts b/sdk/search/search-documents/src/generated/service/operations/index.ts index 896ae33eded4..baac735a9f0d 100644 --- a/sdk/search/search-documents/src/generated/service/operations/index.ts +++ b/sdk/search/search-documents/src/generated/service/operations/index.ts @@ -11,3 +11,4 @@ export * from "./indexers"; export * from "./skillsets"; export * from "./synonymMaps"; export * from "./indexes"; +export * from "./aliases"; diff --git a/sdk/search/search-documents/src/generated/service/operationsInterfaces/aliases.ts b/sdk/search/search-documents/src/generated/service/operationsInterfaces/aliases.ts new file mode 100644 index 000000000000..6248725ff47f --- /dev/null +++ b/sdk/search/search-documents/src/generated/service/operationsInterfaces/aliases.ts @@ -0,0 +1,68 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + SearchAlias, + AliasesCreateOptionalParams, + AliasesCreateResponse, + AliasesListOptionalParams, + AliasesListResponse, + AliasesCreateOrUpdateOptionalParams, + AliasesCreateOrUpdateResponse, + AliasesDeleteOptionalParams, + AliasesGetOptionalParams, + AliasesGetResponse +} from "../models"; + +/** Interface representing a Aliases. */ +export interface Aliases { + /** + * Creates a new search alias. + * @param alias The definition of the alias to create. + * @param options The options parameters. + */ + create( + alias: SearchAlias, + options?: AliasesCreateOptionalParams + ): Promise; + /** + * Lists all aliases available for a search service. + * @param options The options parameters. + */ + list(options?: AliasesListOptionalParams): Promise; + /** + * Creates a new search alias or updates an alias if it already exists. + * @param aliasName The definition of the alias to create or update. + * @param alias The definition of the alias to create or update. + * @param options The options parameters. + */ + createOrUpdate( + aliasName: string, + alias: SearchAlias, + options?: AliasesCreateOrUpdateOptionalParams + ): Promise; + /** + * Deletes a search alias and its associated mapping to an index. This operation is permanent, with no + * recovery option. The mapped index is untouched by this operation. + * @param aliasName The name of the alias to delete. + * @param options The options parameters. + */ + delete( + aliasName: string, + options?: AliasesDeleteOptionalParams + ): Promise; + /** + * Retrieves an alias definition. + * @param aliasName The name of the alias to retrieve. + * @param options The options parameters. + */ + get( + aliasName: string, + options?: AliasesGetOptionalParams + ): Promise; +} diff --git a/sdk/search/search-documents/src/generated/service/operationsInterfaces/index.ts b/sdk/search/search-documents/src/generated/service/operationsInterfaces/index.ts index 896ae33eded4..baac735a9f0d 100644 --- a/sdk/search/search-documents/src/generated/service/operationsInterfaces/index.ts +++ b/sdk/search/search-documents/src/generated/service/operationsInterfaces/index.ts @@ -11,3 +11,4 @@ export * from "./indexers"; export * from "./skillsets"; export * from "./synonymMaps"; export * from "./indexes"; +export * from "./aliases"; diff --git a/sdk/search/search-documents/src/generated/service/searchServiceClient.ts b/sdk/search/search-documents/src/generated/service/searchServiceClient.ts index 5ce44d36c0d2..c0ca783c925a 100644 --- a/sdk/search/search-documents/src/generated/service/searchServiceClient.ts +++ b/sdk/search/search-documents/src/generated/service/searchServiceClient.ts @@ -12,14 +12,16 @@ import { IndexersImpl, SkillsetsImpl, SynonymMapsImpl, - IndexesImpl + IndexesImpl, + AliasesImpl } from "./operations"; import { DataSources, Indexers, Skillsets, SynonymMaps, - Indexes + Indexes, + Aliases } from "./operationsInterfaces"; import * as Parameters from "./models/parameters"; import * as Mappers from "./models/mappers"; @@ -50,6 +52,7 @@ export class SearchServiceClient extends SearchServiceClientContext { this.skillsets = new SkillsetsImpl(this); this.synonymMaps = new SynonymMapsImpl(this); this.indexes = new IndexesImpl(this); + this.aliases = new AliasesImpl(this); } /** @@ -70,6 +73,7 @@ export class SearchServiceClient extends SearchServiceClientContext { skillsets: Skillsets; synonymMaps: SynonymMaps; indexes: Indexes; + aliases: Aliases; } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); diff --git a/sdk/search/search-documents/src/generated/service/searchServiceClientContext.ts b/sdk/search/search-documents/src/generated/service/searchServiceClientContext.ts index 4e053b4ee6dc..58392678a809 100644 --- a/sdk/search/search-documents/src/generated/service/searchServiceClientContext.ts +++ b/sdk/search/search-documents/src/generated/service/searchServiceClientContext.ts @@ -43,7 +43,7 @@ export class SearchServiceClientContext extends coreClient.ServiceClient { requestContentType: "application/json; charset=utf-8" }; - const packageDetails = `azsdk-js-search-documents/11.3.0-beta.6`; + const packageDetails = `azsdk-js-search-documents/11.3.0-beta.7`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` diff --git a/sdk/search/search-documents/src/index.ts b/sdk/search/search-documents/src/index.ts index fba07342f4dd..0ec2e1240c47 100644 --- a/sdk/search/search-documents/src/index.ts +++ b/sdk/search/search-documents/src/index.ts @@ -115,6 +115,13 @@ export { SearchIndexerDataIdentity, ResetDocumentsOptions, ResetSkillsOptions, + SearchIndexAlias, + CreateAliasOptions, + CreateOrUpdateAliasOptions, + DeleteAliasOptions, + GetAliasOptions, + ListAliasesOptions, + AliasIterator, } from "./serviceModels"; export { default as GeographyPoint } from "./geographyPoint"; export { odata } from "./odata"; @@ -331,6 +338,7 @@ export { SemanticConfiguration, PrioritizedFields, SemanticField, + SearchAlias, } from "./generated/service/models"; export { AzureKeyCredential } from "@azure/core-auth"; export { createSynonymMapFromFile } from "./synonymMapHelper"; diff --git a/sdk/search/search-documents/src/searchIndexClient.ts b/sdk/search/search-documents/src/searchIndexClient.ts index fb74f3127a67..411555306d4c 100644 --- a/sdk/search/search-documents/src/searchIndexClient.ts +++ b/sdk/search/search-documents/src/searchIndexClient.ts @@ -32,6 +32,13 @@ import { IndexNameIterator, SearchIndexStatistics, SearchServiceStatistics, + CreateAliasOptions, + SearchIndexAlias, + CreateOrUpdateAliasOptions, + DeleteAliasOptions, + GetAliasOptions, + ListAliasesOptions, + AliasIterator, } from "./serviceModels"; import * as utils from "./serviceUtils"; import { createSpan } from "./tracing"; @@ -225,6 +232,52 @@ export class SearchIndexClient { }; } + private async *listAliasesPage( + options: ListAliasesOptions = {} + ): AsyncIterableIterator { + const { span, updatedOptions } = createSpan("SearchIndexerClient-listAliases", options); + try { + const result = await this.client.aliases.list(updatedOptions); + yield result.aliases; + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message, + }); + throw e; + } finally { + span.end(); + } + } + + private async *listAliasesAll( + options: ListAliasesOptions = {} + ): AsyncIterableIterator { + for await (const page of this.listAliasesPage(options)) { + yield* page; + } + } + + /** + * Lists all aliases available for a search service. + * @param options - The options parameters. + */ + public listAliases(options: ListAliasesOptions = {}): AliasIterator { + const iter = this.listAliasesAll(options); + + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: () => { + return this.listAliasesPage(options); + }, + }; + } + private async *listIndexesNamesPage( options: ListIndexesOptions = {} ): AsyncIterableIterator { @@ -550,6 +603,114 @@ export class SearchIndexClient { } } + /** + * Creates a new search alias or updates an alias if it already exists. + * @param alias - The definition of the alias to create or update. + * @param options - The options parameters. + */ + public async createOrUpdateAlias( + alias: SearchIndexAlias, + options: CreateOrUpdateAliasOptions = {} + ): Promise { + const { span, updatedOptions } = createSpan("SearchIndexerClient-createOrUpdateAlias", options); + try { + const etag = options.onlyIfUnchanged ? alias.etag : undefined; + + const result = await this.client.aliases.createOrUpdate(alias.name, alias, { + ...updatedOptions, + ifMatch: etag, + }); + return result; + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message, + }); + throw e; + } finally { + span.end(); + } + } + + /** + * Creates a new search alias. + * @param alias - The definition of the alias to create. + * @param options - The options parameters. + */ + public async createAlias( + alias: SearchIndexAlias, + options: CreateAliasOptions = {} + ): Promise { + const { span, updatedOptions } = createSpan("SearchIndexerClient-createAlias", options); + try { + const result = await this.client.aliases.create(alias, updatedOptions); + return result; + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message, + }); + throw e; + } finally { + span.end(); + } + } + + /** + * Deletes a search alias and its associated mapping to an index. This operation is permanent, with no + * recovery option. The mapped index is untouched by this operation. + * @param alias - Alias/Name name of the alias to delete. + * @param options - The options parameters. + */ + public async deleteAlias( + alias: string | SearchIndexAlias, + options: DeleteAliasOptions = {} + ): Promise { + const { span, updatedOptions } = createSpan("SearchIndexerClient-deleteAlias", options); + try { + const aliasName: string = typeof alias === "string" ? alias : alias.name; + const etag = + typeof alias === "string" ? undefined : options.onlyIfUnchanged ? alias.etag : undefined; + + await this.client.aliases.delete(aliasName, { + ...updatedOptions, + ifMatch: etag, + }); + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message, + }); + throw e; + } finally { + span.end(); + } + } + + /** + * Retrieves an alias definition. + * @param aliasName - The name of the alias to retrieve. + * @param options - The options parameters. + */ + public async getAlias( + aliasName: string, + options: GetAliasOptions = {} + ): Promise { + const { span, updatedOptions } = createSpan("SearchIndexerClient-getAlias", options); + try { + const result = await this.client.aliases.get(aliasName, updatedOptions); + return result; + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message, + }); + throw e; + } finally { + span.end(); + } + } + /** * Retrieves statistics about an index, such as the count of documents and the size * of index storage. diff --git a/sdk/search/search-documents/src/serviceModels.ts b/sdk/search/search-documents/src/serviceModels.ts index 2698e0f61054..812c46d3133e 100644 --- a/sdk/search/search-documents/src/serviceModels.ts +++ b/sdk/search/search-documents/src/serviceModels.ts @@ -86,6 +86,7 @@ import { SearchIndexerKnowledgeStore, SearchIndexerCache, SemanticSettings, + SearchAlias, } from "./generated/service/models"; import { PagedAsyncIterableIterator } from "@azure/core-paging"; @@ -207,6 +208,46 @@ export type CreateIndexOptions = OperationOptions; */ export type CreateSkillsetOptions = OperationOptions; +/** + * Options for create alias operation. + */ +export type CreateAliasOptions = OperationOptions; + +/** + * Options for create or update alias operation. + */ +export interface CreateOrUpdateAliasOptions extends OperationOptions { + /** + * If set to true, Resource will be deleted only if the etag matches. + */ + onlyIfUnchanged?: boolean; +} + +/** + * Options for delete alias operation. + */ +export interface DeleteAliasOptions extends OperationOptions { + /** + * If set to true, Resource will be deleted only if the etag matches. + */ + onlyIfUnchanged?: boolean; +} + +/** + * Options for get alias operation. + */ +export type GetAliasOptions = OperationOptions; + +/** + * Options for list aliases operation. + */ +export type ListAliasesOptions = OperationOptions; + +/** + * Search Alias object. + */ +export type SearchIndexAlias = SearchAlias; + /** * Options for create synonymmap operation. */ @@ -935,6 +976,14 @@ export interface SynonymMap { // eslint-disable-next-line @typescript-eslint/ban-types export type IndexIterator = PagedAsyncIterableIterator; +/** + * An iterator for listing the aliases that exist in the Search service. Will make requests + * as needed during iteration. Use .byPage() to make one request to the server + * per iteration. + */ +// eslint-disable-next-line @typescript-eslint/ban-types +export type AliasIterator = PagedAsyncIterableIterator; + /** * An iterator for listing the indexes that exist in the Search service. Will make requests * as needed during iteration. Use .byPage() to make one request to the server diff --git a/sdk/search/search-documents/swagger/Data.md b/sdk/search/search-documents/swagger/Data.md index 8a4f824a687d..0ba66f4c9074 100644 --- a/sdk/search/search-documents/swagger/Data.md +++ b/sdk/search/search-documents/swagger/Data.md @@ -10,7 +10,7 @@ generate-metadata: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../ source-code-folder-path: ./src/generated/data -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/932e261a870475e1a29115f62def7bb84e4d7b38/specification/search/data-plane/Azure.Search/preview/2021-04-30-Preview/searchindex.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d850f41f89530917000d8e6bb463f42bb745b930/specification/search/data-plane/Azure.Search/preview/2021-04-30-Preview/searchindex.json add-credentials: false title: SearchClient use-extension: diff --git a/sdk/search/search-documents/swagger/Service.md b/sdk/search/search-documents/swagger/Service.md index 4adfb6dac3b1..13da17bd7c8a 100644 --- a/sdk/search/search-documents/swagger/Service.md +++ b/sdk/search/search-documents/swagger/Service.md @@ -10,7 +10,7 @@ generate-metadata: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../ source-code-folder-path: ./src/generated/service -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/932e261a870475e1a29115f62def7bb84e4d7b38/specification/search/data-plane/Azure.Search/preview/2021-04-30-Preview/searchservice.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d850f41f89530917000d8e6bb463f42bb745b930/specification/search/data-plane/Azure.Search/preview/2021-04-30-Preview/searchservice.json add-credentials: false use-extension: "@autorest/typescript": "6.0.0-beta.13"