Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OnlyIfUnchanged parameter to CreateUpdate & Delete operations #9056

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions sdk/search/search-documents/review/search-documents.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,30 @@ export type CreateIndexerOptions = OperationOptions;
export type CreateIndexOptions = OperationOptions;

// @public
export type CreateorUpdateDataSourceOptions = OperationOptions & ETagOperationOptions;
export interface CreateorUpdateDataSourceOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type CreateorUpdateIndexerOptions = OperationOptions & ETagOperationOptions;
export interface CreateorUpdateIndexerOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export interface CreateOrUpdateIndexOptions extends OperationOptions, ETagOperationOptions {
export interface CreateOrUpdateIndexOptions extends OperationOptions {
allowIndexDowntime?: boolean;
onlyIfUnchanged?: boolean;
}

// @public
export type CreateOrUpdateSkillsetOptions = OperationOptions & ETagOperationOptions;
export interface CreateOrUpdateSkillsetOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type CreateOrUpdateSynonymMapOptions = OperationOptions & ETagOperationOptions;
export interface CreateOrUpdateSynonymMapOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type CreateSkillsetOptions = OperationOptions;
Expand Down Expand Up @@ -232,22 +241,32 @@ export interface DefaultCognitiveServicesAccount {
}

// @public
export type DeleteDataSourceOptions = OperationOptions & ETagOperationOptions;
export interface DeleteDataSourceOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type DeleteDocumentsOptions = IndexDocuments;

// @public
export type DeleteIndexerOptions = OperationOptions & ETagOperationOptions;
export interface DeleteIndexerOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type DeleteIndexOptions = OperationOptions & ETagOperationOptions;
export interface DeleteIndexOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type DeleteSkillsetOptions = OperationOptions & ETagOperationOptions;
export interface DeleteSkillsetOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export type DeleteSynonymMapOptions = OperationOptions & ETagOperationOptions;
export interface DeleteSynonymMapOptions extends OperationOptions {
onlyIfUnchanged?: boolean;
}

// @public
export interface DictionaryDecompounderTokenFilter {
Expand Down Expand Up @@ -340,11 +359,6 @@ export interface EntityRecognitionSkill {
// @public
export type EntityRecognitionSkillLanguage = 'ar' | 'cs' | 'zh-Hans' | 'zh-Hant' | 'da' | 'nl' | 'en' | 'fi' | 'fr' | 'de' | 'el' | 'hu' | 'it' | 'ja' | 'ko' | 'no' | 'pl' | 'pt-PT' | 'pt-BR' | 'ru' | 'es' | 'sv' | 'tr';

// @public
export interface ETagOperationOptions {
accessCondition?: AccessCondition;
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
}

// @public
export interface FacetResult {
[property: string]: any;
Expand Down
1 change: 0 additions & 1 deletion sdk/search/search-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export {
Skillset,
ListSynonymMapsOptions,
DeleteIndexOptions,
ETagOperationOptions,
AnalyzeTextOptions,
GetIndexOptions,
GetIndexStatisticsOptions,
Expand Down
46 changes: 36 additions & 10 deletions sdk/search/search-documents/src/searchIndexClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,17 @@ export class SearchIndexClient {
): Promise<Index> {
const { span, updatedOptions } = createSpan("SearchIndexClient-createOrUpdateIndex", options);
try {
const etag = options.onlyIfUnchanged ? index.etag : undefined;

const result = await this.client.indexes.createOrUpdate(
index.name,
utils.publicIndexToGeneratedIndex(index),
operationOptionsToRequestOptionsBase(updatedOptions)
{
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
}
);
return utils.generatedIndexToPublicIndex(result);
} catch (e) {
Expand Down Expand Up @@ -371,10 +378,17 @@ export class SearchIndexClient {
options
);
try {
const etag = options.onlyIfUnchanged ? synonymMap.etag : undefined;

const result = await this.client.synonymMaps.createOrUpdate(
synonymMap.name,
utils.publicSynonymMapToGeneratedSynonymMap(synonymMap),
operationOptionsToRequestOptionsBase(updatedOptions)
{
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
}
);
return utils.generatedSynonymMapToPublicSynonymMap(result);
} catch (e) {
Expand All @@ -397,11 +411,15 @@ export class SearchIndexClient {
const { span, updatedOptions } = createSpan("SearchIndexClient-deleteIndex", options);
try {
const indexName: string = typeof index === "string" ? index : index.name;
const etag =
typeof index === "string" ? undefined : options.onlyIfUnchanged ? index.etag : undefined;

await this.client.indexes.deleteMethod(
indexName,
operationOptionsToRequestOptionsBase(updatedOptions)
);
await this.client.indexes.deleteMethod(indexName, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand All @@ -425,11 +443,19 @@ export class SearchIndexClient {
const { span, updatedOptions } = createSpan("SearchIndexClient-deleteSynonymMap", options);
try {
const synonymMapName: string = typeof synonymMap === "string" ? synonymMap : synonymMap.name;
const etag =
typeof synonymMap === "string"
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
? undefined
: options.onlyIfUnchanged
? synonymMap.etag
: undefined;

await this.client.synonymMaps.deleteMethod(
synonymMapName,
operationOptionsToRequestOptionsBase(updatedOptions)
);
await this.client.synonymMaps.deleteMethod(synonymMapName, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand Down
90 changes: 64 additions & 26 deletions sdk/search/search-documents/src/searchIndexerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,14 @@ export class SearchIndexerClient {
options
);
try {
const result = await this.client.indexers.createOrUpdate(
indexer.name,
indexer,
operationOptionsToRequestOptionsBase(updatedOptions)
);
const etag = options.onlyIfUnchanged ? indexer.etag : undefined;

const result = await this.client.indexers.createOrUpdate(indexer.name, indexer, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
return result;
} catch (e) {
span.setStatus({
Expand All @@ -484,11 +487,14 @@ export class SearchIndexerClient {
options
);
try {
const result = await this.client.dataSources.createOrUpdate(
dataSource.name,
dataSource,
operationOptionsToRequestOptionsBase(updatedOptions)
);
const etag = options.onlyIfUnchanged ? dataSource.etag : undefined;

const result = await this.client.dataSources.createOrUpdate(dataSource.name, dataSource, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
return utils.generatedDataSourceToPublicDataSource(result);
} catch (e) {
span.setStatus({
Expand All @@ -515,11 +521,19 @@ export class SearchIndexerClient {
options
);
try {
const etag = options.onlyIfUnchanged ? skillset.etag : undefined;

const result = await this.client.skillsets.createOrUpdate(
skillset.name,
utils.publicSkillsetToGeneratedSkillset(skillset),
operationOptionsToRequestOptionsBase(updatedOptions)
{
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
}
);

return utils.generatedSkillsetToPublicSkillset(result);
} catch (e) {
span.setStatus({
Expand All @@ -544,11 +558,19 @@ export class SearchIndexerClient {
const { span, updatedOptions } = createSpan("SearchIndexerClient-deleteIndexer", options);
try {
const indexerName: string = typeof indexer === "string" ? indexer : indexer.name;

await this.client.indexers.deleteMethod(
indexerName,
operationOptionsToRequestOptionsBase(updatedOptions)
);
const etag =
typeof indexer === "string"
? undefined
: options.onlyIfUnchanged
? indexer.etag
: undefined;

await this.client.indexers.deleteMethod(indexerName, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand All @@ -572,11 +594,19 @@ export class SearchIndexerClient {
const { span, updatedOptions } = createSpan("SearchIndexerClient-deleteDataSource", options);
try {
const dataSourceName: string = typeof dataSource === "string" ? dataSource : dataSource.name;

await this.client.dataSources.deleteMethod(
dataSourceName,
operationOptionsToRequestOptionsBase(updatedOptions)
);
const etag =
typeof dataSource === "string"
? undefined
: options.onlyIfUnchanged
? dataSource.etag
: undefined;

await this.client.dataSources.deleteMethod(dataSourceName, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand All @@ -600,11 +630,19 @@ export class SearchIndexerClient {
const { span, updatedOptions } = createSpan("SearchIndexerClient-deleteSkillset", options);
try {
const skillsetName: string = typeof skillset === "string" ? skillset : skillset.name;

await this.client.skillsets.deleteMethod(
skillsetName,
operationOptionsToRequestOptionsBase(updatedOptions)
);
const etag =
typeof skillset === "string"
? undefined
: options.onlyIfUnchanged
? skillset.etag
: undefined;

await this.client.skillsets.deleteMethod(skillsetName, {
...operationOptionsToRequestOptionsBase(updatedOptions),
accessCondition: {
ifMatch: etag
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand Down
Loading