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

Update pinecone-generated-ts-fetch code along with associated types and unit tests #153

Merged
merged 2 commits into from
Nov 7, 2023

Conversation

austin-denoble
Copy link
Contributor

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

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

…pdate relevant typescript types, fix bug in vectorOperationsProvider, update related unit tests
/**
* The public cloud where you would like your index hosted
*/
cloud: 'gcp' | 'aws' | 'azure';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is aligned with the CreateRequestCloudEnum in the generated code: https://github.com/pinecone-io/pinecone-ts-client/pull/153/files#diff-678ee0ec5845c7d940569446c8f0a4210f8e23c95500729b0788439fd9759749R124

Maybe it makes more sense to just export and reuse that directly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to adjust the spec to somehow export these directly in the compiled code. But this seems okay for now.

Comment on lines 3 to 12
/**
* A partial description of indexes in your project.
*
* For full information about each index, see
* { @link Pinecone.describeIndex }
*/
export type PartialIndexDescription = {
/** The name of the index */
name: string;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My assumption is now that the intent is for the API to return the full objects, we don't want to keep the partial type around. Let me know if that's not the case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, exactly. This was just a placeholder until we could return the full object.

// will allow us us to add more information in the future
// in a non-breaking way.
return names.map((n) => ({ name: n }));
return response.databases || [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried messing with the spec, but this || is mainly to handle the case where the response is an empty array. I could not get the OpenAPI spec to handle that and just return the empty array rather than undefined, so we basically do that here so we don't have to handle an optional response.

Open to feedback.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if the spec generation stuff were easier to massage, it seems smart to be defensive like this.

Comment on lines +30 to +34
export const CloudSchema = Type.Union([
Type.Literal('gcp'),
Type.Literal('aws'),
Type.Literal('azure'),
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There might be a better way of doing this, open to feedback. This also isn't handled gracefully by errorFormatter in validator.ts. I'd like to cut a ticket and update if using literals here is deemed the way to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The specific changes to validator.ts to properly handle errors related to this schema are addressed here: #154

const indexConfigurationParameters: ConfigurationParameters = {
basePath: config.hostUrl,
basePath: config.indexHostUrl,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had updated the name of this field before merging the previous PR (#148), and we apparently didn't have any type safety here as config seemed to be any. The provider was essentially giving basePath: undefined to each instance of Configuration. 🤦‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to see some type safety added here. But the index part of the indexHostUrl name seems a bit redundant if the class is called IndexConfiguration


expect(toThrow).rejects.toThrowError(PineconeArgumentError);
expect(toThrow).rejects.toThrowError(
'The argument to createIndex accepts multiple types. Either 1) 2) 3)'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the errorFormatter issue mentioned below (/src/control/types.ts): https://github.com/pinecone-io/pinecone-ts-client/pull/153/files#diff-cf36f0ee9dc687ce8159fbecd0992953a0c2e646eac44cca76cc2a2ba8246db3R30

We haven't used typebox literals anywhere else and the errorFormatter doesn't play nice.

Copy link
Collaborator

@jhamon jhamon left a comment

Choose a reason for hiding this comment

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

This all looks pretty reasonable to me. I haven't looked at your other PR about validation / enums / literals but this seems fine to merge into spruce and continue iterating on in follow-up PRs.

Comment on lines 3 to 12
/**
* A partial description of indexes in your project.
*
* For full information about each index, see
* { @link Pinecone.describeIndex }
*/
export type PartialIndexDescription = {
/** The name of the index */
name: string;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, exactly. This was just a placeholder until we could return the full object.

// will allow us us to add more information in the future
// in a non-breaking way.
return names.map((n) => ({ name: n }));
return response.databases || [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if the spec generation stuff were easier to massage, it seems smart to be defensive like this.

const indexConfigurationParameters: ConfigurationParameters = {
basePath: config.hostUrl,
basePath: config.indexHostUrl,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to see some type safety added here. But the index part of the indexHostUrl name seems a bit redundant if the class is called IndexConfiguration

@austin-denoble austin-denoble merged commit 5bedda5 into spruce Nov 7, 2023
16 of 19 checks passed
@austin-denoble austin-denoble deleted the adenoble/update-openapi-spec branch November 7, 2023 18:36
austin-denoble added a commit that referenced this pull request Nov 7, 2023
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153

## Problem
When replacing the OpenAPI generated core in a previous revision
(#153), our
`validator` module which handles errors emitted from typebox was not
handling literal types correctly.

We added new union of literal types to support `cloud` values:
```
export const CloudSchema = Type.Union([
  Type.Literal('gcp'),
  Type.Literal('aws'),
  Type.Literal('azure'),
]);
```

When passing an incorrect value for the `cloud` field, validator would
not handle things gracefully:
![Screenshot 2023-11-03 at 7 28 21
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/c2485c24-c898-49eb-81cc-260e3532f299)

The errors emitted from typebox look like this:
![Screenshot 2023-11-03 at 7 31 11
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/2ebbeeca-8a6a-4867-b04e-3cbfb2d1150f)

## Solution
This took a lot of trial and error and testing, but I think this is a
reasonable approach. I'm sure there's a lot more bike shedding and
refactoring we could do in `validator`, but for now it feels most
sensible to try and cater to the typebox schemas we support.

Previously, at the top level of `errorFormatter` we were pulling out all
errors that contained `anyOf` in the schema. We return early with the
assumption that these errors are specific to the shape of the top level
arguments being validated. Generally, these types of errors will not
have an `instancePath`. It is also possible to have `anyOf` errors
relating to a specific property, which in our case is the `cloud` field
on `createIndex`.

- At the top-level of `errorFormatter()` rename `anyOfErrors` to
`anyOfArgumentErrors`, and update the filter to exclude errors with
keyword of `const` or `type`.
- Update `typeErrors()` to handle possible `anyOf` errors with keyword
`const` and `instancePath.length > 1` as these are errors specific to a
property whose type is some set of literal values.
- Update broken unit tests.

## Type of Change
- [X] Bug fix (non-breaking change which fixes an issue)

## Test Plan
Pull this PR down and test using the repl:

```
$ npm run repl
$ await init()

// call createIndex and test that passing invalid cloud values throws correctly
$ await client.createIndex({ name: 'test-index', dimension: 10, cloud: 'gg', region: 'us-east4', capacityMode: 'pod' })

// Uncaught:
// PineconeArgumentError: The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'.
//     at /Users/austin/workspace/pinecone-ts-client/dist/validator.js:239:19
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:67:21
//     at step (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:33:23)
//     at Object.next (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:14:53)
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:8:71
//     at new Promise (<anonymous>)
//     at __awaiter (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:4:12)
//     at Pinecone._createIndex (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:62:40)
//     at Pinecone.createIndex (/Users/austin/workspace/pinecone-ts-client/dist/pinecone.js:243:21)
```
austin-denoble added a commit that referenced this pull request Nov 7, 2023
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153
- #154

## Problem
We want to be able to track usage specific to the spruce release of the
client.

## Solution
- Update `buildUserAgent` logic to check for `packageInfo.release`, and
append to the user agent if present.
- Update `release-spruce-dev` and `release-spruce` workflows to add
`@spruce` to `version.json` during these specific releases.

## Type of Change
- [X] New feature (non-breaking change which adds functionality)

## Test Plan
We will need to release through either the `release-spruce` or
`release-spruce-dev` workflows and validate the `version.json` file has
the proper info, and the `release` is appended to the user agent header.
austin-denoble added a commit that referenced this pull request Dec 27, 2023
…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
austin-denoble added a commit that referenced this pull request Dec 27, 2023
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153

## Problem
When replacing the OpenAPI generated core in a previous revision
(#153), our
`validator` module which handles errors emitted from typebox was not
handling literal types correctly.

We added new union of literal types to support `cloud` values:
```
export const CloudSchema = Type.Union([
  Type.Literal('gcp'),
  Type.Literal('aws'),
  Type.Literal('azure'),
]);
```

When passing an incorrect value for the `cloud` field, validator would
not handle things gracefully:
![Screenshot 2023-11-03 at 7 28 21
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/c2485c24-c898-49eb-81cc-260e3532f299)

The errors emitted from typebox look like this:
![Screenshot 2023-11-03 at 7 31 11
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/2ebbeeca-8a6a-4867-b04e-3cbfb2d1150f)

## Solution
This took a lot of trial and error and testing, but I think this is a
reasonable approach. I'm sure there's a lot more bike shedding and
refactoring we could do in `validator`, but for now it feels most
sensible to try and cater to the typebox schemas we support.

Previously, at the top level of `errorFormatter` we were pulling out all
errors that contained `anyOf` in the schema. We return early with the
assumption that these errors are specific to the shape of the top level
arguments being validated. Generally, these types of errors will not
have an `instancePath`. It is also possible to have `anyOf` errors
relating to a specific property, which in our case is the `cloud` field
on `createIndex`.

- At the top-level of `errorFormatter()` rename `anyOfErrors` to
`anyOfArgumentErrors`, and update the filter to exclude errors with
keyword of `const` or `type`.
- Update `typeErrors()` to handle possible `anyOf` errors with keyword
`const` and `instancePath.length > 1` as these are errors specific to a
property whose type is some set of literal values.
- Update broken unit tests.

## Type of Change
- [X] Bug fix (non-breaking change which fixes an issue)

## Test Plan
Pull this PR down and test using the repl:

```
$ npm run repl
$ await init()

// call createIndex and test that passing invalid cloud values throws correctly
$ await client.createIndex({ name: 'test-index', dimension: 10, cloud: 'gg', region: 'us-east4', capacityMode: 'pod' })

// Uncaught:
// PineconeArgumentError: The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'.
//     at /Users/austin/workspace/pinecone-ts-client/dist/validator.js:239:19
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:67:21
//     at step (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:33:23)
//     at Object.next (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:14:53)
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:8:71
//     at new Promise (<anonymous>)
//     at __awaiter (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:4:12)
//     at Pinecone._createIndex (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:62:40)
//     at Pinecone.createIndex (/Users/austin/workspace/pinecone-ts-client/dist/pinecone.js:243:21)
```
austin-denoble added a commit that referenced this pull request Dec 27, 2023
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153
- #154

## Problem
We want to be able to track usage specific to the spruce release of the
client.

## Solution
- Update `buildUserAgent` logic to check for `packageInfo.release`, and
append to the user agent if present.
- Update `release-spruce-dev` and `release-spruce` workflows to add
`@spruce` to `version.json` during these specific releases.

## Type of Change
- [X] New feature (non-breaking change which adds functionality)

## Test Plan
We will need to release through either the `release-spruce` or
`release-spruce-dev` workflows and validate the `version.json` file has
the proper info, and the `release` is appended to the user agent header.
austin-denoble added a commit that referenced this pull request Jan 13, 2024
…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
austin-denoble added a commit that referenced this pull request Jan 13, 2024
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153

## Problem
When replacing the OpenAPI generated core in a previous revision
(#153), our
`validator` module which handles errors emitted from typebox was not
handling literal types correctly.

We added new union of literal types to support `cloud` values:
```
export const CloudSchema = Type.Union([
  Type.Literal('gcp'),
  Type.Literal('aws'),
  Type.Literal('azure'),
]);
```

When passing an incorrect value for the `cloud` field, validator would
not handle things gracefully:
![Screenshot 2023-11-03 at 7 28 21
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/c2485c24-c898-49eb-81cc-260e3532f299)

The errors emitted from typebox look like this:
![Screenshot 2023-11-03 at 7 31 11
PM](https://github.com/pinecone-io/pinecone-ts-client/assets/119623786/2ebbeeca-8a6a-4867-b04e-3cbfb2d1150f)

## Solution
This took a lot of trial and error and testing, but I think this is a
reasonable approach. I'm sure there's a lot more bike shedding and
refactoring we could do in `validator`, but for now it feels most
sensible to try and cater to the typebox schemas we support.

Previously, at the top level of `errorFormatter` we were pulling out all
errors that contained `anyOf` in the schema. We return early with the
assumption that these errors are specific to the shape of the top level
arguments being validated. Generally, these types of errors will not
have an `instancePath`. It is also possible to have `anyOf` errors
relating to a specific property, which in our case is the `cloud` field
on `createIndex`.

- At the top-level of `errorFormatter()` rename `anyOfErrors` to
`anyOfArgumentErrors`, and update the filter to exclude errors with
keyword of `const` or `type`.
- Update `typeErrors()` to handle possible `anyOf` errors with keyword
`const` and `instancePath.length > 1` as these are errors specific to a
property whose type is some set of literal values.
- Update broken unit tests.

## Type of Change
- [X] Bug fix (non-breaking change which fixes an issue)

## Test Plan
Pull this PR down and test using the repl:

```
$ npm run repl
$ await init()

// call createIndex and test that passing invalid cloud values throws correctly
$ await client.createIndex({ name: 'test-index', dimension: 10, cloud: 'gg', region: 'us-east4', capacityMode: 'pod' })

// Uncaught:
// PineconeArgumentError: The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'.
//     at /Users/austin/workspace/pinecone-ts-client/dist/validator.js:239:19
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:67:21
//     at step (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:33:23)
//     at Object.next (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:14:53)
//     at /Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:8:71
//     at new Promise (<anonymous>)
//     at __awaiter (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:4:12)
//     at Pinecone._createIndex (/Users/austin/workspace/pinecone-ts-client/dist/control/createIndex.js:62:40)
//     at Pinecone.createIndex (/Users/austin/workspace/pinecone-ts-client/dist/pinecone.js:243:21)
```
austin-denoble added a commit that referenced this pull request Jan 13, 2024
_This revision is dependent on a previous branches / PRs. These will
need to be reviewed and merged first:_
- #153
- #154

We want to be able to track usage specific to the spruce release of the
client.

- Update `buildUserAgent` logic to check for `packageInfo.release`, and
append to the user agent if present.
- Update `release-spruce-dev` and `release-spruce` workflows to add
`@spruce` to `version.json` during these specific releases.

- [X] New feature (non-breaking change which adds functionality)

We will need to release through either the `release-spruce` or
`release-spruce-dev` workflows and validate the `version.json` file has
the proper info, and the `release` is appended to the user agent header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants