@azure/search-documents
Version:
Azure client library to use AI Search for node.js and browser.
139 lines (137 loc) • 5.58 kB
JavaScript
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 knowledgeRetrievalClient_exports = {};
__export(knowledgeRetrievalClient_exports, {
KnowledgeRetrievalClient: () => KnowledgeRetrievalClient
});
module.exports = __toCommonJS(knowledgeRetrievalClient_exports);
var import_core_auth = require("@azure/core-auth");
var import_core_rest_pipeline = require("@azure/core-rest-pipeline");
var import_knowledgeBaseRetrievalClient = require("./knowledgeBaseRetrieval/knowledgeBaseRetrievalClient.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 KnowledgeRetrievalClient {
/// Maintenance note: when updating supported API versions,
/// the ContinuationToken logic will need to be updated below.
/**
* The service version to use when communicating with the service.
*/
serviceVersion = utils.defaultServiceVersion;
/**
* The endpoint of the search service
*/
endpoint;
/**
* The name of the knowledge base
*/
knowledgeBaseName;
/**
* @hidden
* A reference to the auto-generated KnowledgeRetrievalClient
*/
client;
/**
* A reference to the internal HTTP pipeline for use with raw requests
*/
pipeline;
/**
* Creates an instance of KnowledgeRetrievalClient.
*
* Example usage:
* ```ts snippet:ReadmeSampleKnowledgeRetrievalClient
* import { KnowledgeRetrievalClient, AzureKeyCredential } from "@azure/search-documents";
*
* const knowledgeRetrievalClient = new KnowledgeRetrievalClient(
* "<endpoint>",
* "<knowledgeBaseName>",
* new AzureKeyCredential("<apiKey>"),
* );
* ```
* @param endpoint - The endpoint of the search service
* @param knowledgeBaseName - The name of the knowledge base
* @param credential - Used to authenticate requests to the service.
* @param options - Used to configure the Search client.
*/
constructor(endpoint, knowledgeBaseName, credential, options = {}) {
this.endpoint = endpoint;
this.knowledgeBaseName = knowledgeBaseName;
const internalClientPipelineOptions = {
...options,
apiVersion: options.serviceVersion ?? utils.defaultServiceVersion,
...{
loggingOptions: {
logger: import_logger.logger.info,
additionalAllowedHeaderNames: [
"elapsed-time",
"Location",
"OData-MaxVersion",
"OData-Version",
"Prefer",
"throttle-reason"
]
}
}
};
this.serviceVersion = options.serviceVersion ?? utils.defaultServiceVersion;
this.client = new import_knowledgeBaseRetrievalClient.KnowledgeBaseRetrievalClient(
endpoint,
credential,
knowledgeBaseName,
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)("none"));
}
async retrieve(retrievalRequest, options = {}) {
return import_tracing.tracingClient.withSpan(
"KnowledgeRetrievalClient-retrieve",
options,
async (updatedOptions) => {
return this.client.retrieve(retrievalRequest, updatedOptions);
}
);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
KnowledgeRetrievalClient
});
//# sourceMappingURL=knowledgeRetrievalClient.js.map