-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review feedback: rename singleton, new indexOperationsBuilder, add PI…
…NECONE_CONTROLLER_HOST environment value and use over the default if provided, update unit tests
- Loading branch information
1 parent
aebf975
commit 2b21bb4
Showing
12 changed files
with
160 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# For testing purposes only | ||
PINECONE_API_KEY="" | ||
PINECONE_ENVIRONMENT="" | ||
PINECONE_CONTROLLER_HOST="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
IndexOperationsApi, | ||
Configuration, | ||
} from '../pinecone-generated-ts-fetch'; | ||
import { queryParamsStringify, buildUserAgent, getFetch } from '../utils'; | ||
import { middleware } from '../utils/middleware'; | ||
import type { PineconeConfiguration } from '../data/types'; | ||
import type { ConfigurationParameters as IndexOperationsApiConfigurationParameters } from '../pinecone-generated-ts-fetch'; | ||
|
||
export const indexOperationsBuilder = ( | ||
config: PineconeConfiguration | ||
): IndexOperationsApi => { | ||
const { apiKey } = config; | ||
const controllerPath = config.controllerHostUrl || 'https://api.pinecone.io'; | ||
const apiConfig: IndexOperationsApiConfigurationParameters = { | ||
basePath: controllerPath, | ||
apiKey, | ||
queryParamsStringify, | ||
headers: { | ||
'User-Agent': buildUserAgent(false), | ||
}, | ||
fetchApi: getFetch(config), | ||
middleware, | ||
}; | ||
|
||
return new IndexOperationsApi(new Configuration(apiConfig)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import { VectorOperationsProvider } from '../vectorOperationsProvider'; | ||
import { HostUrlSingleton } from '../hostUrlSingleton'; | ||
import { IndexHostSingleton } from '../indexHostSingleton'; | ||
|
||
describe('VectorOperationsProvider', () => { | ||
let real; | ||
|
||
beforeAll(() => { | ||
real = HostUrlSingleton.getHostUrl; | ||
real = IndexHostSingleton.getHostUrl; | ||
}); | ||
afterAll(() => { | ||
HostUrlSingleton.getHostUrl = real; | ||
IndexHostSingleton.getHostUrl = real; | ||
}); | ||
beforeEach(() => { | ||
HostUrlSingleton.getHostUrl = jest.fn(); | ||
IndexHostSingleton.getHostUrl = jest.fn(); | ||
}); | ||
afterEach(() => { | ||
HostUrlSingleton._reset(); | ||
IndexHostSingleton._reset(); | ||
}); | ||
|
||
test('makes no API calls on instantiation', async () => { | ||
const config = { | ||
apiKey: 'test-api-key', | ||
}; | ||
new VectorOperationsProvider(config, 'index-name'); | ||
expect(HostUrlSingleton.getHostUrl).not.toHaveBeenCalled(); | ||
expect(IndexHostSingleton.getHostUrl).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('api calls occur only the first time the provide method is called', async () => { | ||
const config = { | ||
apiKey: 'test-api-key', | ||
}; | ||
const provider = new VectorOperationsProvider(config, 'index-name'); | ||
expect(HostUrlSingleton.getHostUrl).not.toHaveBeenCalled(); | ||
expect(IndexHostSingleton.getHostUrl).not.toHaveBeenCalled(); | ||
|
||
const api = await provider.provide(); | ||
expect(HostUrlSingleton.getHostUrl).toHaveBeenCalled(); | ||
expect(IndexHostSingleton.getHostUrl).toHaveBeenCalled(); | ||
|
||
const api2 = await provider.provide(); | ||
expect(HostUrlSingleton.getHostUrl).toHaveBeenCalledTimes(1); | ||
expect(IndexHostSingleton.getHostUrl).toHaveBeenCalledTimes(1); | ||
expect(api).toEqual(api2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.