UNPKG

@pinecone-database/pinecone

Version:

This is the official Node.js SDK for [Pinecone](https://www.pinecone.io), written in TypeScript.

49 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NamespaceOperationsProvider = void 0; const db_data_1 = require("../../pinecone-generated-ts-fetch/db_data"); const utils_1 = require("../../utils"); const indexHostSingleton_1 = require("../indexHostSingleton"); const middleware_1 = require("../../utils/middleware"); class NamespaceOperationsProvider { constructor(config, indexName, indexHostUrl, additionalHeaders) { this.config = config; this.indexName = indexName; this.indexHostUrl = (0, utils_1.normalizeUrl)(indexHostUrl); this.additionalHeaders = additionalHeaders; } async provide() { if (this.namespaceOperations) { return this.namespaceOperations; } // If an indexHostUrl has been manually passed we use that, // otherwise we rely on resolving the host from the IndexHostSingleton if (this.indexHostUrl) { this.namespaceOperations = this.buildNamespaceOperationsConfig(); } else { this.indexHostUrl = await indexHostSingleton_1.IndexHostSingleton.getHostUrl(this.config, this.indexName); this.namespaceOperations = this.buildNamespaceOperationsConfig(); } return this.namespaceOperations; } buildNamespaceOperationsConfig() { const headers = this.additionalHeaders || null; const indexConfigurationParameters = { basePath: this.indexHostUrl, apiKey: this.config.apiKey, queryParamsStringify: utils_1.queryParamsStringify, headers: { 'User-Agent': (0, utils_1.buildUserAgent)(this.config), 'X-Pinecone-Api-Version': db_data_1.X_PINECONE_API_VERSION, ...headers, }, fetchApi: (0, utils_1.getFetch)(this.config), middleware: middleware_1.middleware, }; const indexConfiguration = new db_data_1.Configuration(indexConfigurationParameters); return new db_data_1.NamespaceOperationsApi(indexConfiguration); } } exports.NamespaceOperationsProvider = NamespaceOperationsProvider; //# sourceMappingURL=namespacesOperationsProvider.js.map