Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regenerate OpenAPI core #203

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataOperationsProvider } from '../dataOperationsProvider';
import { IndexHostSingleton } from '../indexHostSingleton';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See dataOperationsProvider file below, renamed to align with the new API class.


describe('VectorOperationsProvider', () => {
describe('DataOperationsProvider', () => {
let real;

beforeAll(() => {
Expand All @@ -21,15 +21,15 @@ describe('VectorOperationsProvider', () => {
const config = {
apiKey: 'test-api-key',
};
new VectorOperationsProvider(config, 'index-name');
new DataOperationsProvider(config, 'index-name');
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');
const provider = new DataOperationsProvider(config, 'index-name');
expect(IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();

const api = await provider.provide();
Expand All @@ -45,17 +45,17 @@ describe('VectorOperationsProvider', () => {
apiKey: 'test-api-key',
};
const indexHostUrl = 'http://index-host-url';
const provider = new VectorOperationsProvider(
const provider = new DataOperationsProvider(
config,
'index-name',
indexHostUrl
);

jest.spyOn(provider, 'buildVectorOperationsConfig');
jest.spyOn(provider, 'buildDataOperationsConfig');

await provider.provide();

expect(IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();
expect(provider.buildVectorOperationsConfig).toHaveBeenCalled();
expect(provider.buildDataOperationsConfig).toHaveBeenCalled();
});
});
6 changes: 3 additions & 3 deletions src/data/__tests__/deleteAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { setupDeleteSuccess } from './deleteOne.test';

describe('deleteAll', () => {
test('calls the openapi delete endpoint, passing deleteAll with target namespace', async () => {
const { VoaProvider, VOA } = setupDeleteSuccess(undefined);
const { DataProvider, DPA } = setupDeleteSuccess(undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed these across tests to keep things consistent with the new DataPlaneApi class.


const deleteAllFn = deleteAll(VoaProvider, 'namespace');
const deleteAllFn = deleteAll(DataProvider, 'namespace');
const returned = await deleteAllFn();

expect(returned).toBe(void 0);
expect(VOA._delete).toHaveBeenCalledWith({
expect(DPA._delete).toHaveBeenCalledWith({
deleteRequest: { deleteAll: true, namespace: 'namespace' },
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/data/__tests__/deleteMany.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { setupDeleteSuccess } from './deleteOne.test';

describe('deleteMany', () => {
test('calls the openapi delete endpoint, passing ids with target namespace', async () => {
const { VoaProvider, VOA } = setupDeleteSuccess(undefined);
const { DataProvider, DPA } = setupDeleteSuccess(undefined);

const deleteManyFn = deleteMany(VoaProvider, 'namespace');
const deleteManyFn = deleteMany(DataProvider, 'namespace');
const returned = await deleteManyFn(['123', '456', '789']);

expect(returned).toBe(void 0);
expect(VOA._delete).toHaveBeenCalledWith({
expect(DPA._delete).toHaveBeenCalledWith({
deleteRequest: { ids: ['123', '456', '789'], namespace: 'namespace' },
});
});

test('calls the openapi delete endpoint, passing filter with target namespace', async () => {
const { VOA, VoaProvider } = setupDeleteSuccess(undefined);
const { DPA, DataProvider } = setupDeleteSuccess(undefined);

const deleteManyFn = deleteMany(VoaProvider, 'namespace');
const deleteManyFn = deleteMany(DataProvider, 'namespace');
const returned = await deleteManyFn({ genre: 'ambient' });

expect(returned).toBe(void 0);
expect(VOA._delete).toHaveBeenCalledWith({
expect(DPA._delete).toHaveBeenCalledWith({
deleteRequest: { filter: { genre: 'ambient' }, namespace: 'namespace' },
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/data/__tests__/deleteOne.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { deleteOne } from '../deleteOne';
import type {
DeleteOperationRequest,
VectorOperationsApi,
DataPlaneApi,
} from '../../pinecone-generated-ts-fetch';
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataOperationsProvider } from '../dataOperationsProvider';

const setupDeleteResponse = (response, isSuccess) => {
const fakeDelete: (req: DeleteOperationRequest) => Promise<object> = jest
.fn()
.mockImplementation(() =>
isSuccess ? Promise.resolve(response) : Promise.reject(response)
);
const VOA = { _delete: fakeDelete } as VectorOperationsApi;
const VoaProvider = { provide: async () => VOA } as VectorOperationsProvider;
return { VOA, VoaProvider };
const DPA = { _delete: fakeDelete } as DataPlaneApi;
const DataProvider = { provide: async () => DPA } as DataOperationsProvider;
return { DPA, DataProvider };
};
export const setupDeleteSuccess = (response) => {
return setupDeleteResponse(response, true);
Expand All @@ -24,13 +24,13 @@ export const setupDeleteFailure = (response) => {

describe('deleteOne', () => {
test('calls the openapi delete endpoint, passing target namespace and the vector id to delete', async () => {
const { VoaProvider, VOA } = setupDeleteSuccess(undefined);
const { DataProvider, DPA } = setupDeleteSuccess(undefined);

const deleteOneFn = deleteOne(VoaProvider, 'namespace');
const deleteOneFn = deleteOne(DataProvider, 'namespace');
const returned = await deleteOneFn('123');

expect(returned).toBe(void 0);
expect(VOA._delete).toHaveBeenCalledWith({
expect(DPA._delete).toHaveBeenCalledWith({
deleteRequest: { ids: ['123'], namespace: 'namespace' },
});
});
Expand Down
18 changes: 9 additions & 9 deletions src/data/__tests__/describeIndexStats.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describeIndexStats } from '../describeIndexStats';
import { VectorOperationsApi } from '../../pinecone-generated-ts-fetch';
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataPlaneApi } from '../../pinecone-generated-ts-fetch';
import { DataOperationsProvider } from '../dataOperationsProvider';
import type { DescribeIndexStatsOperationRequest } from '../../pinecone-generated-ts-fetch';

const setupResponse = (response, isSuccess) => {
Expand All @@ -11,19 +11,19 @@ const setupResponse = (response, isSuccess) => {
.mockImplementation(() =>
isSuccess ? Promise.resolve(response) : Promise.reject(response)
);
const VOA = {
const DPA = {
describeIndexStats: fakeDescribeIndexStats,
} as VectorOperationsApi;
const VoaProvider = { provide: async () => VOA } as VectorOperationsProvider;
return { VOA, VoaProvider };
} as DataPlaneApi;
const DataProvider = { provide: async () => DPA } as DataOperationsProvider;
return { DPA, DataProvider };
};
const setupSuccess = (response) => {
return setupResponse(response, true);
};

describe('describeIndexStats', () => {
test('calls the openapi describe_index_stats endpoint passing filter if provided', async () => {
const { VOA, VoaProvider } = setupSuccess({
const { DPA, DataProvider } = setupSuccess({
namespaces: {
'': { vectorCount: 50 },
},
Expand All @@ -32,7 +32,7 @@ describe('describeIndexStats', () => {
totalVectorCount: 50,
});

const describeIndexStatsFn = describeIndexStats(VoaProvider);
const describeIndexStatsFn = describeIndexStats(DataProvider);
const returned = await describeIndexStatsFn({
filter: { genre: 'classical' },
});
Expand All @@ -46,7 +46,7 @@ describe('describeIndexStats', () => {
indexFullness: 0,
totalRecordCount: 50,
});
expect(VOA.describeIndexStats).toHaveBeenCalledWith({
expect(DPA.describeIndexStats).toHaveBeenCalledWith({
describeIndexStatsRequest: { filter: { genre: 'classical' } },
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/data/__tests__/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FetchCommand } from '../fetch';
import { VectorOperationsApi } from '../../pinecone-generated-ts-fetch';
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataPlaneApi } from '../../pinecone-generated-ts-fetch';
import { DataOperationsProvider } from '../dataOperationsProvider';
import type {
FetchRequest,
FetchResponse,
Expand All @@ -12,22 +12,22 @@ const setupResponse = (response, isSuccess) => {
.mockImplementation(() =>
isSuccess ? Promise.resolve(response) : Promise.reject(response)
);
const VOA = { fetch: fakeFetch } as VectorOperationsApi;
const VoaProvider = { provide: async () => VOA } as VectorOperationsProvider;
const cmd = new FetchCommand(VoaProvider, 'namespace');
return { VOA, VoaProvider, cmd };
const DPA = { fetch: fakeFetch } as DataPlaneApi;
const DataProvider = { provide: async () => DPA } as DataOperationsProvider;
const cmd = new FetchCommand(DataProvider, 'namespace');
return { DPA, DataProvider, cmd };
};
const setupSuccess = (response) => {
return setupResponse(response, true);
};

describe('fetch', () => {
test('calls the openapi fetch endpoint, passing target namespace', async () => {
const { VOA, cmd } = setupSuccess({ vectors: [] });
const { DPA, cmd } = setupSuccess({ vectors: [] });
const returned = await cmd.run(['1', '2']);

expect(returned).toEqual({ records: [], namespace: '' });
expect(VOA.fetch).toHaveBeenCalledWith({
expect(DPA.fetch).toHaveBeenCalledWith({
ids: ['1', '2'],
namespace: 'namespace',
});
Expand Down
12 changes: 6 additions & 6 deletions src/data/__tests__/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UpdateCommand } from '../update';
import { VectorOperationsApi } from '../../pinecone-generated-ts-fetch';
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataPlaneApi } from '../../pinecone-generated-ts-fetch';
import { DataOperationsProvider } from '../dataOperationsProvider';
import type { UpdateOperationRequest } from '../../pinecone-generated-ts-fetch';

const setupResponse = (response, isSuccess) => {
Expand All @@ -9,10 +9,10 @@ const setupResponse = (response, isSuccess) => {
.mockImplementation(() =>
isSuccess ? Promise.resolve(response) : Promise.reject(response)
);
const VOA = { update: fakeUpdate } as VectorOperationsApi;
const VoaProvider = { provide: async () => VOA } as VectorOperationsProvider;
const cmd = new UpdateCommand(VoaProvider, 'namespace');
return { fakeUpdate, VOA, VoaProvider, cmd };
const DPA = { update: fakeUpdate } as DataPlaneApi;
const DataProvider = { provide: async () => DPA } as DataOperationsProvider;
const cmd = new UpdateCommand(DataProvider, 'namespace');
return { fakeUpdate, DPA, DataProvider, cmd };
};
const setupSuccess = (response) => {
return setupResponse(response, true);
Expand Down
12 changes: 6 additions & 6 deletions src/data/__tests__/upsert.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { UpsertCommand } from '../upsert';
import { VectorOperationsApi } from '../../pinecone-generated-ts-fetch';
import { DataPlaneApi } from '../../pinecone-generated-ts-fetch';
import type { UpsertOperationRequest } from '../../pinecone-generated-ts-fetch';
import { VectorOperationsProvider } from '../vectorOperationsProvider';
import { DataOperationsProvider } from '../dataOperationsProvider';

const setupResponse = (response, isSuccess) => {
const fakeUpsert: (req: UpsertOperationRequest) => Promise<object> = jest
.fn()
.mockImplementation(() =>
isSuccess ? Promise.resolve(response) : Promise.reject(response)
);
const VOA = { upsert: fakeUpsert } as VectorOperationsApi;
const VoaProvider = { provide: async () => VOA } as VectorOperationsProvider;
const cmd = new UpsertCommand(VoaProvider, 'namespace');
const DPA = { upsert: fakeUpsert } as DataPlaneApi;
const DataProvider = { provide: async () => DPA } as DataOperationsProvider;
const cmd = new UpsertCommand(DataProvider, 'namespace');

return { fakeUpsert, VOA, VoaProvider, cmd };
return { fakeUpsert, DPA, DataProvider, cmd };
};
const setupSuccess = (response) => {
return setupResponse(response, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PineconeConfiguration } from './types';
import {
Configuration,
ConfigurationParameters,
VectorOperationsApi,
DataPlaneApi,
} from '../pinecone-generated-ts-fetch';
import {
queryParamsStringify,
Expand All @@ -13,11 +13,11 @@ import {
import { IndexHostSingleton } from './indexHostSingleton';
import { middleware } from '../utils/middleware';

export class VectorOperationsProvider {
export class DataOperationsProvider {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this class and file to DataOperationsProvider.

private config: PineconeConfiguration;
private indexName: string;
private indexHostUrl?: string;
private vectorOperations?: VectorOperationsApi;
private dataOperations?: DataPlaneApi;

constructor(
config: PineconeConfiguration,
Expand All @@ -30,27 +30,27 @@ export class VectorOperationsProvider {
}

async provide() {
if (this.vectorOperations) {
return this.vectorOperations;
if (this.dataOperations) {
return this.dataOperations;
}

// If an indexHostUrl has been manually passed we use that,
// otherwise we rely on resolving the host from the IndexHostSingleton
if (this.indexHostUrl) {
this.vectorOperations = this.buildVectorOperationsConfig();
this.dataOperations = this.buildDataOperationsConfig();
} else {
this.indexHostUrl = await IndexHostSingleton.getHostUrl(
this.config,
this.indexName
);

this.vectorOperations = this.buildVectorOperationsConfig();
this.dataOperations = this.buildDataOperationsConfig();
}

return this.vectorOperations;
return this.dataOperations;
}

buildVectorOperationsConfig() {
buildDataOperationsConfig() {
const indexConfigurationParameters: ConfigurationParameters = {
basePath: this.indexHostUrl,
apiKey: this.config.apiKey,
Expand All @@ -63,8 +63,8 @@ export class VectorOperationsProvider {
};

const indexConfiguration = new Configuration(indexConfigurationParameters);
const vectorOperations = new VectorOperationsApi(indexConfiguration);
const dataOperations = new DataPlaneApi(indexConfiguration);

return vectorOperations;
return dataOperations;
}
}
4 changes: 2 additions & 2 deletions src/data/deleteAll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VectorOperationsProvider } from './vectorOperationsProvider';
import { DataOperationsProvider } from './dataOperationsProvider';

export const deleteAll = (
apiProvider: VectorOperationsProvider,
apiProvider: DataOperationsProvider,
namespace: string
) => {
return async (): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions src/data/deleteMany.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VectorOperationsProvider } from './vectorOperationsProvider';
import { DataOperationsProvider } from './dataOperationsProvider';
import { buildConfigValidator } from '../validator';
import { Type } from '@sinclair/typebox';
import type { DeleteRequest } from '../pinecone-generated-ts-fetch/models/DeleteRequest';
Expand Down Expand Up @@ -35,7 +35,7 @@ export type DeleteManyOptions =
| DeleteManyByFilterOptions;

export const deleteMany = (
apiProvider: VectorOperationsProvider,
apiProvider: DataOperationsProvider,
namespace: string
) => {
const validator = buildConfigValidator(DeleteManySchema, 'deleteMany');
Expand Down
4 changes: 2 additions & 2 deletions src/data/deleteOne.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VectorOperationsProvider } from './vectorOperationsProvider';
import { DataOperationsProvider } from './dataOperationsProvider';
import { buildConfigValidator } from '../validator';
import { RecordIdSchema } from './types';
import type { RecordId } from './types';
Expand All @@ -11,7 +11,7 @@ import type { RecordId } from './types';
export type DeleteOneOptions = RecordId;

export const deleteOne = (
apiProvider: VectorOperationsProvider,
apiProvider: DataOperationsProvider,
namespace: string
) => {
const validator = buildConfigValidator(RecordIdSchema, 'deleteOne');
Expand Down
Loading
Loading