UNPKG

@azure/search-documents

Version:
679 lines 29.8 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { searchIndexerDataSourceConnectionSerializer, searchIndexerDataSourceConnectionDeserializer, listDataSourcesResultDeserializer, searchIndexerSerializer, searchIndexerDeserializer, listIndexersResultDeserializer, searchIndexerStatusDeserializer, searchIndexerSkillsetSerializer, searchIndexerSkillsetDeserializer, listSkillsetsResultDeserializer, } from "../../models/azure/search/documents/indexes/models.js"; import { errorResponseDeserializer } from "../../models/azure/search/documents/models.js"; import { expandUrlTemplate } from "../../static-helpers/urlTemplate.js"; import { createRestError, operationOptionsToRequestParameters } from "@azure-rest/core-client"; export function _createSkillsetSend(context, skillset, options = { requestOptions: {} }) { const path = expandUrlTemplate("/skillsets{?api%2Dversion}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).post({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerSkillsetSerializer(skillset), }); } export async function _createSkillsetDeserialize(result) { const expectedStatuses = ["201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerSkillsetDeserializer(result.body); } /** Creates a new skillset in a search service. */ export async function createSkillset(context, skillset, options = { requestOptions: {} }) { const result = await _createSkillsetSend(context, skillset, options); return _createSkillsetDeserialize(result); } export function _getSkillsetsSend(context, options = { requestOptions: {} }) { const path = expandUrlTemplate("/skillsets{?api%2Dversion,%24select}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", "%24select": options?.select, }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getSkillsetsDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return listSkillsetsResultDeserializer(result.body); } /** List all skillsets in a search service. */ export async function getSkillsets(context, options = { requestOptions: {} }) { const result = await _getSkillsetsSend(context, options); return _getSkillsetsDeserialize(result); } export function _getSkillsetSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/skillsets('{skillsetName}'){?api%2Dversion}", { skillsetName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getSkillsetDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerSkillsetDeserializer(result.body); } /** Retrieves a skillset in a search service. */ export async function getSkillset(context, name, options = { requestOptions: {} }) { const result = await _getSkillsetSend(context, name, options); return _getSkillsetDeserialize(result); } export function _deleteSkillsetSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/skillsets('{skillsetName}'){?api%2Dversion}", { skillsetName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).delete({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _deleteSkillsetDeserialize(result) { const expectedStatuses = ["204", "404"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return; } /** Deletes a skillset in a search service. */ export async function deleteSkillset(context, name, options = { requestOptions: {} }) { const result = await _deleteSkillsetSend(context, name, options); return _deleteSkillsetDeserialize(result); } export function _createOrUpdateSkillsetSend(context, skillset, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/skillsets('{skillsetName}'){?api%2Dversion}", { skillsetName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).put({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), prefer: "return=representation", ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerSkillsetSerializer(skillset), }); } export async function _createOrUpdateSkillsetDeserialize(result) { const expectedStatuses = ["200", "201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerSkillsetDeserializer(result.body); } /** Creates a new skillset in a search service or updates the skillset if it already exists. */ export async function createOrUpdateSkillset(context, skillset, name, options = { requestOptions: {} }) { const result = await _createOrUpdateSkillsetSend(context, skillset, name, options); return _createOrUpdateSkillsetDeserialize(result); } export function _getIndexerStatusSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}')/search.status{?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getIndexerStatusDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerStatusDeserializer(result.body); } /** Returns the current status and execution history of an indexer. */ export async function getIndexerStatus(context, name, options = { requestOptions: {} }) { const result = await _getIndexerStatusSend(context, name, options); return _getIndexerStatusDeserialize(result); } export function _createIndexerSend(context, indexer, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers{?api%2Dversion}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).post({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerSerializer(indexer), }); } export async function _createIndexerDeserialize(result) { const expectedStatuses = ["201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDeserializer(result.body); } /** Creates a new indexer. */ export async function createIndexer(context, indexer, options = { requestOptions: {} }) { const result = await _createIndexerSend(context, indexer, options); return _createIndexerDeserialize(result); } export function _getIndexersSend(context, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers{?api%2Dversion,%24select}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", "%24select": options?.select, }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getIndexersDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return listIndexersResultDeserializer(result.body); } /** Lists all indexers available for a search service. */ export async function getIndexers(context, options = { requestOptions: {} }) { const result = await _getIndexersSend(context, options); return _getIndexersDeserialize(result); } export function _getIndexerSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}'){?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getIndexerDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDeserializer(result.body); } /** Retrieves an indexer definition. */ export async function getIndexer(context, name, options = { requestOptions: {} }) { const result = await _getIndexerSend(context, name, options); return _getIndexerDeserialize(result); } export function _deleteIndexerSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}'){?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).delete({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _deleteIndexerDeserialize(result) { const expectedStatuses = ["204", "404"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return; } /** Deletes an indexer. */ export async function deleteIndexer(context, name, options = { requestOptions: {} }) { const result = await _deleteIndexerSend(context, name, options); return _deleteIndexerDeserialize(result); } export function _createOrUpdateIndexerSend(context, indexer, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}'){?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).put({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), prefer: "return=representation", ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerSerializer(indexer), }); } export async function _createOrUpdateIndexerDeserialize(result) { const expectedStatuses = ["200", "201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDeserializer(result.body); } /** Creates a new indexer or updates an indexer if it already exists. */ export async function createOrUpdateIndexer(context, indexer, name, options = { requestOptions: {} }) { const result = await _createOrUpdateIndexerSend(context, indexer, name, options); return _createOrUpdateIndexerDeserialize(result); } export function _runIndexerSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}')/search.run{?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).post({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _runIndexerDeserialize(result) { const expectedStatuses = ["202"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return; } /** Runs an indexer on-demand. */ export async function runIndexer(context, name, options = { requestOptions: {} }) { const result = await _runIndexerSend(context, name, options); return _runIndexerDeserialize(result); } export function _resetIndexerSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/indexers('{indexerName}')/search.reset{?api%2Dversion}", { indexerName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).post({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _resetIndexerDeserialize(result) { const expectedStatuses = ["204"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return; } /** Resets the change tracking state associated with an indexer. */ export async function resetIndexer(context, name, options = { requestOptions: {} }) { const result = await _resetIndexerSend(context, name, options); return _resetIndexerDeserialize(result); } export function _createDataSourceConnectionSend(context, dataSourceConnection, options = { requestOptions: {} }) { const path = expandUrlTemplate("/datasources{?api%2Dversion}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).post({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerDataSourceConnectionSerializer(dataSourceConnection), }); } export async function _createDataSourceConnectionDeserialize(result) { const expectedStatuses = ["201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDataSourceConnectionDeserializer(result.body); } /** Creates a new datasource. */ export async function createDataSourceConnection(context, dataSourceConnection, options = { requestOptions: {} }) { const result = await _createDataSourceConnectionSend(context, dataSourceConnection, options); return _createDataSourceConnectionDeserialize(result); } export function _getDataSourceConnectionsSend(context, options = { requestOptions: {} }) { const path = expandUrlTemplate("/datasources{?api%2Dversion,%24select}", { "api%2Dversion": context.apiVersion ?? "2026-04-01", "%24select": options?.select, }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getDataSourceConnectionsDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return listDataSourcesResultDeserializer(result.body); } /** Lists all datasources available for a search service. */ export async function getDataSourceConnections(context, options = { requestOptions: {} }) { const result = await _getDataSourceConnectionsSend(context, options); return _getDataSourceConnectionsDeserialize(result); } export function _getDataSourceConnectionSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/datasources('{dataSourceName}'){?api%2Dversion}", { dataSourceName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).get({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _getDataSourceConnectionDeserialize(result) { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDataSourceConnectionDeserializer(result.body); } /** Retrieves a datasource definition. */ export async function getDataSourceConnection(context, name, options = { requestOptions: {} }) { const result = await _getDataSourceConnectionSend(context, name, options); return _getDataSourceConnectionDeserialize(result); } export function _deleteDataSourceConnectionSend(context, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/datasources('{dataSourceName}'){?api%2Dversion}", { dataSourceName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).delete({ ...operationOptionsToRequestParameters(options), headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, }); } export async function _deleteDataSourceConnectionDeserialize(result) { const expectedStatuses = ["204", "404"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return; } /** Deletes a datasource. */ export async function deleteDataSourceConnection(context, name, options = { requestOptions: {} }) { const result = await _deleteDataSourceConnectionSend(context, name, options); return _deleteDataSourceConnectionDeserialize(result); } export function _createOrUpdateDataSourceConnectionSend(context, dataSource, name, options = { requestOptions: {} }) { const path = expandUrlTemplate("/datasources('{dataSourceName}'){?api%2Dversion}", { dataSourceName: name, "api%2Dversion": context.apiVersion ?? "2026-04-01", }, { allowReserved: options?.requestOptions?.skipUrlEncoding, }); return context.path(path).put({ ...operationOptionsToRequestParameters(options), contentType: "application/json", headers: { ...(options?.accept !== undefined ? { accept: !options?.accept ? options?.accept : "application/json;odata.metadata=minimal", } : {}), ...(options?.ifMatch !== undefined ? { "if-match": options?.ifMatch } : {}), ...(options?.ifNoneMatch !== undefined ? { "if-none-match": options?.ifNoneMatch } : {}), prefer: "return=representation", ...(options?.clientRequestId !== undefined ? { "x-ms-client-request-id": options?.clientRequestId } : {}), ...options.requestOptions?.headers, }, body: searchIndexerDataSourceConnectionSerializer(dataSource), }); } export async function _createOrUpdateDataSourceConnectionDeserialize(result) { const expectedStatuses = ["200", "201"]; if (!expectedStatuses.includes(result.status)) { const error = createRestError(result); error.details = errorResponseDeserializer(result.body); throw error; } return searchIndexerDataSourceConnectionDeserializer(result.body); } /** Creates a new datasource or updates a datasource if it already exists. */ export async function createOrUpdateDataSourceConnection(context, dataSource, name, options = { requestOptions: {} }) { const result = await _createOrUpdateDataSourceConnectionSend(context, dataSource, name, options); return _createOrUpdateDataSourceConnectionDeserialize(result); } //# sourceMappingURL=operations.js.map