Skip to content

Commit

Permalink
Update pinecone-generated-ts-fetch code along with associated types a…
Browse files Browse the repository at this point in the history
…nd unit tests (#153)

## Problem
We need to update the generated client code
(`pinecone-generated-ts-fetch`) to align with upcoming API changes.

## Solution
- Regenerate and replace the contents of `/pinecone-generated-ts-fetch`.
- Update relevant types and unit tests, primarily `createIndex` and
`listIndexes`.
- Add new unit tests to the `createIndex.validation` suite focused on
new required fields in `CreateIndexOptions`.
- **Bonus:** Fix for `vectorOperationsProvider` - TS wasn't properly
inferring types within `buildVectorOperationsConfig`, and we were
passing `undefined` to `indexConfigurationParameters.basePath`.

## Type of Change
- [X] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [X] This change requires a documentation update
  • Loading branch information
austin-denoble committed Jan 13, 2024
1 parent 0df868a commit 71492ba
Show file tree
Hide file tree
Showing 30 changed files with 714 additions and 88 deletions.
3 changes: 2 additions & 1 deletion src/control/__tests__/configureIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { configureIndex } from '../configureIndex';
import { IndexOperationsApi } from '../../pinecone-generated-ts-fetch';
import type { ConfigureIndexRequest } from '../../pinecone-generated-ts-fetch';
import type { IndexMeta } from '../../index';

describe('configureIndex', () => {
test('calls the openapi configure endpoint', async () => {
const fakeConfigure: (req: ConfigureIndexRequest) => Promise<string> =
const fakeConfigure: (req: ConfigureIndexRequest) => Promise<IndexMeta> =
jest.fn();
const IOA = { configureIndex: fakeConfigure } as IndexOperationsApi;

Expand Down
7 changes: 5 additions & 2 deletions src/control/__tests__/createCollection.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { createCollection } from '../createCollection';
import { PineconeArgumentError } from '../../errors';
import { IndexOperationsApi } from '../../pinecone-generated-ts-fetch';
import type { CreateCollectionOperationRequest as CCOR } from '../../pinecone-generated-ts-fetch';
import type {
CreateCollectionOperationRequest as CCOR,
ListIndexes200Response,
} from '../../pinecone-generated-ts-fetch';

const setOpenAPIResponse = (fakeCreateCollectionResponse) => {
const fakeCreateCollection: (req: CCOR) => Promise<string> = jest
.fn()
.mockImplementation(fakeCreateCollectionResponse);
const fakeListIndexes: () => Promise<string[]> = jest
const fakeListIndexes: () => Promise<ListIndexes200Response> = jest
.fn()
.mockImplementation(() => Promise.resolve(['foo', 'bar']));
const IOA = {
Expand Down
17 changes: 16 additions & 1 deletion src/control/__tests__/createIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const setupCreateIndexResponse = (
isCreateIndexSuccess = true,
isDescribeIndexSuccess = true
) => {
const fakeCreateIndex: (req: CreateIndexRequest) => Promise<string> = jest
const fakeCreateIndex: (req: CreateIndexRequest) => Promise<IndexMeta> = jest
.fn()
.mockImplementation(() =>
isCreateIndexSuccess
Expand Down Expand Up @@ -52,13 +52,19 @@ describe('createIndex', () => {
const returned = await createIndex(IOA)({
name: 'index-name',
dimension: 10,
cloud: 'gcp',
region: 'us-east1',
capacityMode: 'pod',
});

expect(returned).toBe(void 0);
expect(IOA.createIndex).toHaveBeenCalledWith({
createRequest: {
name: 'index-name',
dimension: 10,
capacityMode: 'pod',
cloud: 'gcp',
region: 'us-east1',
},
});
});
Expand All @@ -81,6 +87,9 @@ describe('createIndex', () => {
const returned = await createIndex(IOA)({
name: 'index-name',
dimension: 10,
cloud: 'gcp',
region: 'us-east1',
capacityMode: 'pod',
waitUntilReady: true,
});

Expand All @@ -89,6 +98,9 @@ describe('createIndex', () => {
createRequest: {
name: 'index-name',
dimension: 10,
cloud: 'gcp',
region: 'us-east1',
capacityMode: 'pod',
waitUntilReady: true,
},
});
Expand Down Expand Up @@ -116,6 +128,9 @@ describe('createIndex', () => {
const returned = createIndex(IOA)({
name: 'index-name',
dimension: 10,
cloud: 'gcp',
region: 'us-east1',
capacityMode: 'pod',
waitUntilReady: true,
});

Expand Down
Loading

0 comments on commit 71492ba

Please sign in to comment.