UNPKG

@azure/search-documents

Version:
484 lines (483 loc) 18.1 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var searchIndexerClient_exports = {}; __export(searchIndexerClient_exports, { SearchIndexerClient: () => SearchIndexerClient }); module.exports = __toCommonJS(searchIndexerClient_exports); var import_core_auth = require("@azure/core-auth"); var import_core_rest_pipeline = require("@azure/core-rest-pipeline"); var import_searchIndexerClient = require("./searchIndexer/searchIndexerClient.js"); var import_logger = require("./logger.js"); var import_odataMetadataPolicy = require("./odataMetadataPolicy.js"); var import_searchApiKeyCredentialPolicy = require("./searchApiKeyCredentialPolicy.js"); var import_searchAudience = require("./searchAudience.js"); var utils = __toESM(require("./serviceUtils.js")); var import_tracing = require("./tracing.js"); class SearchIndexerClient { /** * The API version to use when communicating with the service. */ serviceVersion = utils.defaultServiceVersion; /** * The API version to use when communicating with the service. * @deprecated use {@Link serviceVersion} instead */ apiVersion = utils.defaultServiceVersion; /** * The endpoint of the search service */ endpoint; /** * @hidden * A reference to the auto-generated SearchServiceClient */ client; /** * A reference to the internal HTTP pipeline for use with raw requests */ pipeline; /** * Creates an instance of SearchIndexerClient. * * Example usage: * ```ts snippet:ReadmeSampleSearchIndexerClient * import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents"; * * const indexerClient = new SearchIndexerClient("<endpoint>", new AzureKeyCredential("<apiKey>")); * ``` * @param endpoint - The endpoint of the search service * @param credential - Used to authenticate requests to the service. * @param options - Used to configure the Search client. */ constructor(endpoint, credential, options = {}) { this.endpoint = endpoint; const internalClientPipelineOptions = { ...options, apiVersion: options.serviceVersion ?? options.apiVersion ?? utils.defaultServiceVersion, ...{ loggingOptions: { logger: import_logger.logger.info, additionalAllowedHeaderNames: [ "elapsed-time", "Location", "OData-MaxVersion", "OData-Version", "Prefer", "throttle-reason" ] } } }; this.serviceVersion = options.serviceVersion ?? options.apiVersion ?? utils.defaultServiceVersion; this.apiVersion = this.serviceVersion; this.client = new import_searchIndexerClient.SearchIndexerClient(this.endpoint, credential, internalClientPipelineOptions); this.pipeline = this.client.pipeline; this.pipeline.removePolicy({ name: import_core_rest_pipeline.bearerTokenAuthenticationPolicyName }); if ((0, import_core_auth.isTokenCredential)(credential)) { const scope = options.audience ? `${options.audience}/.default` : `${import_searchAudience.KnownSearchAudience.AzurePublicCloud}/.default`; this.client.pipeline.addPolicy( (0, import_core_rest_pipeline.bearerTokenAuthenticationPolicy)({ credential, scopes: scope }) ); } else { this.client.pipeline.addPolicy((0, import_searchApiKeyCredentialPolicy.createSearchApiKeyCredentialPolicy)(credential)); } this.client.pipeline.addPolicy((0, import_odataMetadataPolicy.createOdataMetadataPolicy)("minimal")); } /** * Retrieves a list of existing indexers in the service. * @param options - Options to the list indexers operation. */ async listIndexers(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listIndexers", options, async (updatedOptions) => { const result = await this.client.getIndexers(updatedOptions); return result.indexers.map(utils.generatedSearchIndexerToPublicSearchIndexer); } ); } /** * Retrieves a list of names of existing indexers in the service. * @param options - Options to the list indexers operation. */ // eslint-disable-next-line @azure/azure-sdk/ts-naming-options async listIndexersNames(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listIndexersNames", options, async (updatedOptions) => { const result = await this.client.getIndexers({ ...updatedOptions, select: "name" }); return result.indexers.map((idx) => idx.name); } ); } /** * Retrieves a list of existing data sources in the service. * @param options - Options to the list indexers operation. */ async listDataSourceConnections(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listDataSourceConnections", options, async (updatedOptions) => { const result = await this.client.getDataSourceConnections(updatedOptions); return result.dataSources.map(utils.generatedDataSourceToPublicDataSource); } ); } /** * Retrieves a list of names of existing data sources in the service. * @param options - Options to the list indexers operation. */ async listDataSourceConnectionsNames(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listDataSourceConnectionsNames", options, async (updatedOptions) => { const result = await this.client.getDataSourceConnections({ ...updatedOptions, select: "name" }); return result.dataSources.map((ds) => ds.name); } ); } /** * Retrieves a list of existing Skillsets in the service. * @param options - Options to the list Skillsets operation. */ async listSkillsets(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listSkillsets", options, async (updatedOptions) => { const result = await this.client.getSkillsets(updatedOptions); return result.skillsets.map(utils.generatedSkillsetToPublicSkillset); } ); } /** * Retrieves a list of names of existing Skillsets in the service. * @param options - Options to the list Skillsets operation. */ // eslint-disable-next-line @azure/azure-sdk/ts-naming-options async listSkillsetsNames(options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-listSkillsetsNames", options, async (updatedOptions) => { const result = await this.client.getSkillsets({ ...updatedOptions, select: "name" }); return result.skillsets.map((sks) => sks.name); } ); } /** * Retrieves information about an Indexer. * @param indexerName - The name of the Indexer. * @param options - Additional optional arguments. */ async getIndexer(indexerName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-getIndexer", options, async (updatedOptions) => { const result = await this.client.getIndexer(indexerName, updatedOptions); return utils.generatedSearchIndexerToPublicSearchIndexer(result); } ); } /** * Retrieves information about a DataSource * @param dataSourceName - The name of the DataSource * @param options - Additional optional arguments */ async getDataSourceConnection(dataSourceConnectionName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-getDataSourceConnection", options, async (updatedOptions) => { const result = await this.client.getDataSourceConnection( dataSourceConnectionName, updatedOptions ); return utils.generatedDataSourceToPublicDataSource(result); } ); } /** * Retrieves information about an Skillset. * @param indexName - The name of the Skillset. * @param options - Additional optional arguments. */ async getSkillset(skillsetName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-getSkillset", options, async (updatedOptions) => { const result = await this.client.getSkillset(skillsetName, updatedOptions); return utils.generatedSkillsetToPublicSkillset(result); } ); } /** * Creates a new indexer in a search service. * @param indexer - The indexer definition to create in a search service. * @param options - Additional optional arguments. */ async createIndexer(indexer, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createIndexer", options, async (updatedOptions) => { const result = await this.client.createIndexer( utils.publicSearchIndexerToGeneratedSearchIndexer(indexer), updatedOptions ); return utils.generatedSearchIndexerToPublicSearchIndexer(result); } ); } /** * Creates a new dataSource in a search service. * @param dataSourceConnection - The dataSource definition to create in a search service. * @param options - Additional optional arguments. */ async createDataSourceConnection(dataSourceConnection, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createDataSourceConnection", options, async (updatedOptions) => { const result = await this.client.createDataSourceConnection( utils.publicDataSourceToGeneratedDataSource(dataSourceConnection), updatedOptions ); return utils.generatedDataSourceToPublicDataSource(result); } ); } /** * Creates a new skillset in a search service. * @param skillset - The skillset containing one or more skills to create in a search service. * @param options - Additional optional arguments. */ async createSkillset(skillset, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createSkillset", options, async (updatedOptions) => { const result = await this.client.createSkillset( utils.publicSkillsetToGeneratedSkillset(skillset), updatedOptions ); return utils.generatedSkillsetToPublicSkillset(result); } ); } /** * Creates a new indexer or modifies an existing one. * @param indexer - The information describing the indexer to be created/updated. * @param options - Additional optional arguments. */ async createOrUpdateIndexer(indexer, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createOrUpdateIndexer", options, async (updatedOptions) => { const { onlyIfUnchanged, ...restOptions } = updatedOptions; const etag = onlyIfUnchanged ? indexer.etag : void 0; const result = await this.client.createOrUpdateIndexer( utils.publicSearchIndexerToGeneratedSearchIndexer(indexer), indexer.name, { ...restOptions, ifMatch: etag } ); return utils.generatedSearchIndexerToPublicSearchIndexer(result); } ); } /** * Creates a new datasource or modifies an existing one. * @param dataSourceConnection - The information describing the datasource to be created/updated. * @param options - Additional optional arguments. */ async createOrUpdateDataSourceConnection(dataSourceConnection, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createOrUpdateDataSourceConnection", options, async (updatedOptions) => { const etag = options.onlyIfUnchanged ? dataSourceConnection.etag : void 0; const result = await this.client.createOrUpdateDataSourceConnection( utils.publicDataSourceToGeneratedDataSource(dataSourceConnection), dataSourceConnection.name, { ...updatedOptions, ifMatch: etag } ); return utils.generatedDataSourceToPublicDataSource(result); } ); } /** * Creates a new Skillset or modifies an existing one. * @param skillset - The information describing the index to be created. * @param options - Additional optional arguments. */ async createOrUpdateSkillset(skillset, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-createOrUpdateSkillset", options, async (updatedOptions) => { const etag = options.onlyIfUnchanged ? skillset.etag : void 0; const result = await this.client.createOrUpdateSkillset( utils.publicSkillsetToGeneratedSkillset(skillset), skillset.name, { ...updatedOptions, ifMatch: etag } ); return utils.generatedSkillsetToPublicSkillset(result); } ); } /** * Deletes an existing indexer. * @param indexer - Indexer/Name of the indexer to delete. * @param options - Additional optional arguments. */ async deleteIndexer(indexer, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-deleteIndexer", options, async (updatedOptions) => { const indexerName = typeof indexer === "string" ? indexer : indexer.name; const etag = typeof indexer === "string" ? void 0 : options.onlyIfUnchanged ? indexer.etag : void 0; await this.client.deleteIndexer(indexerName, { ...updatedOptions, ifMatch: etag }); } ); } /** * Deletes an existing datasource. * @param dataSource - Datasource/Name of the datasource to delete. * @param options - Additional optional arguments. */ async deleteDataSourceConnection(dataSourceConnection, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-deleteDataSourceConnection", options, async (updatedOptions) => { const dataSourceConnectionName = typeof dataSourceConnection === "string" ? dataSourceConnection : dataSourceConnection.name; const etag = typeof dataSourceConnection === "string" ? void 0 : options.onlyIfUnchanged ? dataSourceConnection.etag : void 0; await this.client.deleteDataSourceConnection(dataSourceConnectionName, { ...updatedOptions, ifMatch: etag }); } ); } /** * Deletes an existing Skillset. * @param skillset - Skillset/Name of the Skillset to delete. * @param options - Additional optional arguments. */ async deleteSkillset(skillset, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-deleteSkillset", options, async (updatedOptions) => { const skillsetName = typeof skillset === "string" ? skillset : skillset.name; const etag = typeof skillset === "string" ? void 0 : options.onlyIfUnchanged ? skillset.etag : void 0; await this.client.deleteSkillset(skillsetName, { ...updatedOptions, ifMatch: etag }); } ); } /** * Returns the current status and execution history of an indexer. * @param indexerName - The name of the indexer. * @param options - Additional optional arguments. */ async getIndexerStatus(indexerName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-getIndexerStatus", options, async (updatedOptions) => { return this.client.getIndexerStatus(indexerName, updatedOptions); } ); } /** * Resets the change tracking state associated with an indexer. * @param indexerName - The name of the indexer to reset. * @param options - Additional optional arguments. */ async resetIndexer(indexerName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-resetIndexer", options, async (updatedOptions) => { await this.client.resetIndexer(indexerName, updatedOptions); } ); } /** * Runs an indexer on-demand. * @param indexerName - The name of the indexer to run. * @param options - Additional optional arguments. */ async runIndexer(indexerName, options = {}) { return import_tracing.tracingClient.withSpan( "SearchIndexerClient-runIndexer", options, async (updatedOptions) => { await this.client.runIndexer(indexerName, updatedOptions); } ); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { SearchIndexerClient }); //# sourceMappingURL=searchIndexerClient.js.map