From 8000736a3cedc7c750f6648ef7d334ffaacb3c56 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Wed, 1 Nov 2023 15:16:54 -0400 Subject: [PATCH 1/5] re-generate and update openapi core in pinecone-generated-ts-fetch, update relevant typescript types, fix bug in vectorOperationsProvider, update related unit tests --- src/control/listIndexes.ts | 3 +-- src/data/vectorOperationsProvider.ts | 2 +- src/integration/control/listIndexes.test.ts | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/control/listIndexes.ts b/src/control/listIndexes.ts index f861daec..d8cd81a8 100644 --- a/src/control/listIndexes.ts +++ b/src/control/listIndexes.ts @@ -1,5 +1,4 @@ import { IndexOperationsApi } from '../pinecone-generated-ts-fetch'; -import type { IndexListMeta } from '../pinecone-generated-ts-fetch'; /** * A description of indexes in your project. @@ -27,7 +26,7 @@ export type IndexListDescription = { export type IndexList = Array; export const listIndexes = (api: IndexOperationsApi) => { - return async (): Promise> => { + return async (): Promise => { const response = await api.listIndexes(); return response.databases || []; diff --git a/src/data/vectorOperationsProvider.ts b/src/data/vectorOperationsProvider.ts index 0f69de6b..c8628db5 100644 --- a/src/data/vectorOperationsProvider.ts +++ b/src/data/vectorOperationsProvider.ts @@ -39,7 +39,7 @@ export class VectorOperationsProvider { buildVectorOperationsConfig(config: IndexConfiguration) { const indexConfigurationParameters: ConfigurationParameters = { - basePath: config.hostUrl, + basePath: config.indexHostUrl, apiKey: config.apiKey, queryParamsStringify, headers: { diff --git a/src/integration/control/listIndexes.test.ts b/src/integration/control/listIndexes.test.ts index d2b51a6f..1590c064 100644 --- a/src/integration/control/listIndexes.test.ts +++ b/src/integration/control/listIndexes.test.ts @@ -27,6 +27,10 @@ describe('list indexes', () => { expect(indexes).toBeDefined(); expect(indexes?.length).toBeGreaterThan(0); +<<<<<<< HEAD expect(indexes?.map((i) => i.name)).toContain(indexName); +======= + expect(indexes?.map((i) => i.database.name)).toContain(indexName); +>>>>>>> 20de0e0 (re-generate and update openapi core in pinecone-generated-ts-fetch, update relevant typescript types, fix bug in vectorOperationsProvider, update related unit tests) }); }); From 8a6f69e04a0b798a8b3c30970896020ce17aef19 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Fri, 3 Nov 2023 18:50:46 -0400 Subject: [PATCH 2/5] update validator to handle typebox schemas where we are using literals --- .../__tests__/createIndex.validation.test.ts | 4 +- src/validator.ts | 52 ++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/control/__tests__/createIndex.validation.test.ts b/src/control/__tests__/createIndex.validation.test.ts index 7d397fdd..60950946 100644 --- a/src/control/__tests__/createIndex.validation.test.ts +++ b/src/control/__tests__/createIndex.validation.test.ts @@ -180,7 +180,7 @@ describe('createIndex argument validations', () => { expect(toThrow).rejects.toThrowError(PineconeArgumentError); expect(toThrow).rejects.toThrowError( - 'The argument to createIndex accepts multiple types. Either 1) 2) 3)' + "The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'." ); }); @@ -196,7 +196,7 @@ describe('createIndex argument validations', () => { expect(toThrow).rejects.toThrowError(PineconeArgumentError); expect(toThrow).rejects.toThrowError( - 'The argument to createIndex accepts multiple types. Either 1) 2) 3)' + "The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'." ); }); diff --git a/src/validator.ts b/src/validator.ts index d2251575..25202421 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -97,12 +97,46 @@ const typeErrors = ( messageParts: Array ) => { const typeErrorsList: Array = []; + const anyOfConstPropErrors: Array = errors.filter( + (error) => + error.schemaPath.indexOf('anyOf') > -1 && + error.keyword === 'const' && + error.instancePath.length > 0 + ); let errorCount = 0; + // handle possible literal types first + const propErrorGroups: { [key: string]: Array } = {}; + if (anyOfConstPropErrors.length > 0) { + for (const error of anyOfConstPropErrors) { + const constValue = error.instancePath.slice(1); + + if (propErrorGroups[constValue]) { + propErrorGroups[constValue].push(error); + } else { + propErrorGroups[constValue] = [error]; + } + } + const properties = Object.keys(propErrorGroups); + + properties.forEach((property) => { + const constValueErrors = propErrorGroups[property]; + + typeErrorsList.push( + `property '${property}' is a constant which must be equal to one of: ` + + Object.values(constValueErrors) + .map((group) => `'${group.params.allowedValue}'`) + .join(', ') + ); + }); + } + + // typebox also emits type errors for each value of a literal so we want to exclude these + const anyOfKeys = Object.keys(propErrorGroups); for (let i = 0; i < errors.length; i++) { const e = errors[i]; - if (e.keyword === 'type') { + if (e.keyword === 'type' && !anyOfKeys.includes(e.instancePath.slice(1))) { errorCount += 1; if (errorCount <= maxErrors) { formatIndividualError(e, typeErrorsList); @@ -181,13 +215,19 @@ const validationErrors = ( }; export const errorFormatter = (subject: string, errors: Array) => { - const anyOfErrors = errors.filter( + const messageParts: Array = []; + + const anyOfArgumentErrors = errors.filter( (error) => - error.schemaPath.indexOf('anyOf') > -1 && error.keyword !== 'anyOf' + error.schemaPath.indexOf('anyOf') > -1 && + error.keyword !== 'anyOf' && + error.keyword !== 'const' && + error.keyword !== 'type' ); - if (anyOfErrors.length > 0) { + + if (anyOfArgumentErrors.length > 0) { const groups = {}; - for (const error of anyOfErrors) { + for (const error of anyOfArgumentErrors) { const schemaPathMatch = schemaPathGroupNumberRegex.exec(error.schemaPath); const groupNumber = schemaPathMatch ? schemaPathMatch[1] : 'unknown'; // Remove the anyOf portion of the schema path to avoid infinite loop @@ -214,8 +254,6 @@ export const errorFormatter = (subject: string, errors: Array) => { ); } - const messageParts: Array = []; - neverErrors(subject, errors, messageParts); missingPropertiesErrors(subject, errors, messageParts); typeErrors(subject, errors, messageParts); From 7b819ac385ea2821e474461040e8490ba4aba097 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Tue, 7 Nov 2023 13:47:51 -0500 Subject: [PATCH 3/5] rebase, tweak vectorOperationsProvider unit test --- src/data/vectorOperationsProvider.ts | 2 +- src/integration/control/listIndexes.test.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/data/vectorOperationsProvider.ts b/src/data/vectorOperationsProvider.ts index c8628db5..0f69de6b 100644 --- a/src/data/vectorOperationsProvider.ts +++ b/src/data/vectorOperationsProvider.ts @@ -39,7 +39,7 @@ export class VectorOperationsProvider { buildVectorOperationsConfig(config: IndexConfiguration) { const indexConfigurationParameters: ConfigurationParameters = { - basePath: config.indexHostUrl, + basePath: config.hostUrl, apiKey: config.apiKey, queryParamsStringify, headers: { diff --git a/src/integration/control/listIndexes.test.ts b/src/integration/control/listIndexes.test.ts index 1590c064..d2b51a6f 100644 --- a/src/integration/control/listIndexes.test.ts +++ b/src/integration/control/listIndexes.test.ts @@ -27,10 +27,6 @@ describe('list indexes', () => { expect(indexes).toBeDefined(); expect(indexes?.length).toBeGreaterThan(0); -<<<<<<< HEAD expect(indexes?.map((i) => i.name)).toContain(indexName); -======= - expect(indexes?.map((i) => i.database.name)).toContain(indexName); ->>>>>>> 20de0e0 (re-generate and update openapi core in pinecone-generated-ts-fetch, update relevant typescript types, fix bug in vectorOperationsProvider, update related unit tests) }); }); From c655eae5349a8ecc3a84f8c55f3d0d745efbe3d0 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Tue, 7 Nov 2023 13:52:30 -0500 Subject: [PATCH 4/5] rebase and cleanup --- src/control/__tests__/createIndex.validation.test.ts | 4 ++-- src/validator.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/control/__tests__/createIndex.validation.test.ts b/src/control/__tests__/createIndex.validation.test.ts index 60950946..d49f1007 100644 --- a/src/control/__tests__/createIndex.validation.test.ts +++ b/src/control/__tests__/createIndex.validation.test.ts @@ -180,7 +180,7 @@ describe('createIndex argument validations', () => { expect(toThrow).rejects.toThrowError(PineconeArgumentError); expect(toThrow).rejects.toThrowError( - "The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'." + "The argument to createIndex had type errors: property 'cloud' must be equal to one of: 'gcp', 'aws', 'azure'." ); }); @@ -196,7 +196,7 @@ describe('createIndex argument validations', () => { expect(toThrow).rejects.toThrowError(PineconeArgumentError); expect(toThrow).rejects.toThrowError( - "The argument to createIndex had type errors: property 'cloud' is a constant which must be equal to one of: 'gcp', 'aws', 'azure'." + "The argument to createIndex had type errors: property 'cloud' must be equal to one of: 'gcp', 'aws', 'azure'." ); }); diff --git a/src/validator.ts b/src/validator.ts index 25202421..9173119d 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -123,7 +123,7 @@ const typeErrors = ( const constValueErrors = propErrorGroups[property]; typeErrorsList.push( - `property '${property}' is a constant which must be equal to one of: ` + + `property '${property}' must be equal to one of: ` + Object.values(constValueErrors) .map((group) => `'${group.params.allowedValue}'`) .join(', ') From f8a068eeed6a2c18c17e05964e893013a87f61b7 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Tue, 7 Nov 2023 14:18:38 -0500 Subject: [PATCH 5/5] clean up errorFormatter a bit --- src/validator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validator.ts b/src/validator.ts index 9173119d..f6138abb 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -215,8 +215,6 @@ const validationErrors = ( }; export const errorFormatter = (subject: string, errors: Array) => { - const messageParts: Array = []; - const anyOfArgumentErrors = errors.filter( (error) => error.schemaPath.indexOf('anyOf') > -1 && @@ -254,6 +252,8 @@ export const errorFormatter = (subject: string, errors: Array) => { ); } + const messageParts: Array = []; + neverErrors(subject, errors, messageParts); missingPropertiesErrors(subject, errors, messageParts); typeErrors(subject, errors, messageParts);