diff --git a/lib/src/generated/client.dart b/lib/src/generated/client.dart index 48a18c0..2590aae 100644 --- a/lib/src/generated/client.dart +++ b/lib/src/generated/client.dart @@ -58,23 +58,26 @@ class PineconeClientException implements io.HttpException { /// Client for Pinecone API /// -/// `host`: Override host URL - else defaults to server host defined in spec +/// `baseUrl`: Override baseUrl URL - else defaults to server url defined in spec /// /// `client`: Override HTTP client to use for requests class PineconeClient { PineconeClient({ this.apiKey = '', - String? host, + String? baseUrl, http.Client? client, - }) { + }) : assert( + baseUrl == null || baseUrl.startsWith('http'), + 'baseUrl must start with http', + ) { + // Ensure trailing slash is removed from baseUrl + this.baseUrl = baseUrl?.replaceAll(RegExp(r'/$'), ''); // Create a retry client this.client = RetryClient(client ?? http.Client()); - // Ensure trailing slash is removed from host - this.host = host?.replaceAll(RegExp(r'/$'), ''); } - /// User provided override for host URL - late final String? host; + /// User provided override for baseUrl URL + late final String? baseUrl; /// HTTP client for requests late final http.Client client; @@ -115,7 +118,7 @@ class PineconeClient { /// Reusable request method Future _request({ - required String host, + required String baseUrl, required String path, required HttpMethod method, Map queryParams = const {}, @@ -125,15 +128,14 @@ class PineconeClient { String responseType = '', Object? body, }) async { - // Override with the user provided host - host = this.host ?? host; + // Override with the user provided baseUrl + baseUrl = this.baseUrl ?? baseUrl; - // Ensure a host is provided - if (host.isEmpty) { - throw Exception( - '\n\nHost is required, but none defined in spec or provided by user\n', - ); - } + // Ensure a baseUrl is provided + assert( + baseUrl.isNotEmpty, + 'baseUrl is required, but none defined in spec or provided by user', + ); // Ensure query parameters are strings or iterable of strings queryParams = queryParams.map((key, value) { @@ -145,30 +147,13 @@ class PineconeClient { }); // Build the request URI - final secure = Uri.parse(host).scheme == 'https'; - Uri uri; - String authority; - if (host.contains('http')) { - authority = Uri.parse(host).authority; - } else { - authority = Uri.parse(Uri.https(host).toString()).authority; - } - if (secure) { - uri = Uri.https( - authority, - path, - queryParams.isEmpty ? null : queryParams, - ); - } else { - uri = Uri.http( - authority, - path, - queryParams.isEmpty ? null : queryParams, - ); + Uri uri = Uri.parse(baseUrl + path); + if (queryParams.isNotEmpty) { + uri = uri.replace(queryParameters: queryParams); } // Build the headers - Map headers = {}..addAll(headerParams); + Map headers = {...headerParams}; // Define the request type being sent to server if (requestType.isNotEmpty) { @@ -263,7 +248,7 @@ class PineconeClient { String environment = 'us-west1-gcp-free', }) async { final r = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/collections', method: HttpMethod.get, isMultipart: false, @@ -294,7 +279,7 @@ class PineconeClient { required CreateCollectionRequest request, }) async { final _ = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/collections', method: HttpMethod.post, isMultipart: false, @@ -325,7 +310,7 @@ class PineconeClient { required String collectionName, }) async { final r = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/collections/$collectionName', method: HttpMethod.get, isMultipart: false, @@ -356,7 +341,7 @@ class PineconeClient { required String collectionName, }) async { final _ = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/collections/$collectionName', method: HttpMethod.delete, isMultipart: false, @@ -383,7 +368,7 @@ class PineconeClient { String environment = 'us-west1-gcp-free', }) async { final r = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/databases', method: HttpMethod.get, isMultipart: false, @@ -414,7 +399,7 @@ class PineconeClient { required CreateIndexRequest request, }) async { final _ = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/databases', method: HttpMethod.post, isMultipart: false, @@ -445,7 +430,7 @@ class PineconeClient { required String indexName, }) async { final r = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/databases/$indexName', method: HttpMethod.get, isMultipart: false, @@ -476,7 +461,7 @@ class PineconeClient { required String indexName, }) async { final _ = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/databases/$indexName', method: HttpMethod.delete, isMultipart: false, @@ -509,7 +494,7 @@ class PineconeClient { required ConfigureIndexRequest request, }) async { final _ = await _request( - host: 'https://controller.${environment}.pinecone.io', + baseUrl: 'https://controller.${environment}.pinecone.io', path: '/databases/$indexName', method: HttpMethod.patch, isMultipart: false, @@ -546,7 +531,8 @@ class PineconeClient { IndexStatsRequest? request, }) async { final r = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/describe_index_stats', method: HttpMethod.post, isMultipart: false, @@ -584,7 +570,8 @@ class PineconeClient { required QueryRequest request, }) async { final r = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/query', method: HttpMethod.post, isMultipart: false, @@ -622,7 +609,8 @@ class PineconeClient { required DeleteRequest request, }) async { final _ = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/vectors/delete', method: HttpMethod.post, isMultipart: false, @@ -662,7 +650,8 @@ class PineconeClient { String? namespace, }) async { final r = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/vectors/fetch', method: HttpMethod.get, isMultipart: false, @@ -703,7 +692,8 @@ class PineconeClient { required UpdateRequest request, }) async { final _ = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/vectors/update', method: HttpMethod.post, isMultipart: false, @@ -740,7 +730,8 @@ class PineconeClient { required UpsertRequest request, }) async { final r = await _request( - host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', + baseUrl: + 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io', path: '/vectors/upsert', method: HttpMethod.post, isMultipart: false, diff --git a/oas/index_api/configure_index.dart b/oas/index_api/configure_index.dart index 5c0c699..f66449d 100644 --- a/oas/index_api/configure_index.dart +++ b/oas/index_api/configure_index.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Configure index operation final configureIndex = Operation( diff --git a/oas/index_api/create_collection.dart b/oas/index_api/create_collection.dart index 6fb3eaf..dc91f7d 100644 --- a/oas/index_api/create_collection.dart +++ b/oas/index_api/create_collection.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Create collection operation final createCollection = Operation( diff --git a/oas/index_api/create_index.dart b/oas/index_api/create_index.dart index bc497a9..6e5f645 100644 --- a/oas/index_api/create_index.dart +++ b/oas/index_api/create_index.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Create index operation final createIndex = Operation( diff --git a/oas/index_api/delete_collection.dart b/oas/index_api/delete_collection.dart index 040491c..d6312ac 100644 --- a/oas/index_api/delete_collection.dart +++ b/oas/index_api/delete_collection.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Delete collection operation final deleteCollection = Operation( diff --git a/oas/index_api/delete_index.dart b/oas/index_api/delete_index.dart index 2ac1c56..0faa740 100644 --- a/oas/index_api/delete_index.dart +++ b/oas/index_api/delete_index.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Delete index operation final deleteIndex = Operation( diff --git a/oas/index_api/describe_collection.dart b/oas/index_api/describe_collection.dart index cb45ec1..780d634 100644 --- a/oas/index_api/describe_collection.dart +++ b/oas/index_api/describe_collection.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Describe collection operation final describeCollection = Operation( diff --git a/oas/index_api/describe_index.dart b/oas/index_api/describe_index.dart index a0b0f17..299dcd3 100644 --- a/oas/index_api/describe_index.dart +++ b/oas/index_api/describe_index.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// Describe index operation final describeIndex = Operation( diff --git a/oas/index_api/list_collections.dart b/oas/index_api/list_collections.dart index 6b1b51b..f02c41f 100644 --- a/oas/index_api/list_collections.dart +++ b/oas/index_api/list_collections.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// List collections operation final listCollections = Operation( diff --git a/oas/index_api/list_indexes.dart b/oas/index_api/list_indexes.dart index 9866fdf..b7a8084 100644 --- a/oas/index_api/list_indexes.dart +++ b/oas/index_api/list_indexes.dart @@ -1,4 +1,4 @@ -part of pinecone_index_api; +part of 'api.dart'; /// List indexes operation final listIndexes = Operation( diff --git a/oas/schema/collection.dart b/oas/schema/collection.dart index 5bf2b9e..4e2d9e9 100644 --- a/oas/schema/collection.dart +++ b/oas/schema/collection.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Collection object final schemaCollection = Schema.object( diff --git a/oas/schema/collection_status.dart b/oas/schema/collection_status.dart index 7a37a78..d5572f1 100644 --- a/oas/schema/collection_status.dart +++ b/oas/schema/collection_status.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// An enumeration of the available pod types. final schemaCollectionStatus = Schema.enumeration( diff --git a/oas/schema/configure_index_request.dart b/oas/schema/configure_index_request.dart index e7a39f8..f59d5a6 100644 --- a/oas/schema/configure_index_request.dart +++ b/oas/schema/configure_index_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Create collection request object final schemaConfigureIndexRequest = Schema.object( diff --git a/oas/schema/create_collection_request.dart b/oas/schema/create_collection_request.dart index 44f6a5a..ad7e16e 100644 --- a/oas/schema/create_collection_request.dart +++ b/oas/schema/create_collection_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Create collection request object final schemaCreateCollectionRequest = Schema.object( diff --git a/oas/schema/create_index_request.dart b/oas/schema/create_index_request.dart index 6c4c58b..093534a 100644 --- a/oas/schema/create_index_request.dart +++ b/oas/schema/create_index_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Create index request object final schemaCreateIndexRequest = Schema.object( diff --git a/oas/schema/delete_request.dart b/oas/schema/delete_request.dart index eb7a39f..30c7e0b 100644 --- a/oas/schema/delete_request.dart +++ b/oas/schema/delete_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Create collection request object final schemaDeleteRequest = Schema.object( diff --git a/oas/schema/fetch_response.dart b/oas/schema/fetch_response.dart index 36e33de..3650cae 100644 --- a/oas/schema/fetch_response.dart +++ b/oas/schema/fetch_response.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector fetch response object final schemaFetchResponse = Schema.object( diff --git a/oas/schema/index.dart b/oas/schema/index.dart index 812504e..2ea3f9d 100644 --- a/oas/schema/index.dart +++ b/oas/schema/index.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Index object final schemaIndex = Schema.object( diff --git a/oas/schema/index_database.dart b/oas/schema/index_database.dart index c04d88a..0c2e7cf 100644 --- a/oas/schema/index_database.dart +++ b/oas/schema/index_database.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Index database object final schemaIndexDatabase = Schema.object( diff --git a/oas/schema/index_state.dart b/oas/schema/index_state.dart index 64632ef..cfa5174 100644 --- a/oas/schema/index_state.dart +++ b/oas/schema/index_state.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// An enumeration of the current index state. final schemaIndexState = Schema.enumeration( diff --git a/oas/schema/index_stats.dart b/oas/schema/index_stats.dart index 8cda081..7a999a5 100644 --- a/oas/schema/index_stats.dart +++ b/oas/schema/index_stats.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Index stats object final schemaIndexStats = Schema.object( diff --git a/oas/schema/index_stats_request.dart b/oas/schema/index_stats_request.dart index 92ac391..c439c54 100644 --- a/oas/schema/index_stats_request.dart +++ b/oas/schema/index_stats_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Described index statistics request object final schemaIndexStatsRequest = Schema.object( diff --git a/oas/schema/index_status.dart b/oas/schema/index_status.dart index 37d6405..686ee2f 100644 --- a/oas/schema/index_status.dart +++ b/oas/schema/index_status.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Index status object final schemaIndexStatus = Schema.object( diff --git a/oas/schema/pod_type.dart b/oas/schema/pod_type.dart index 1a966a3..52782f6 100644 --- a/oas/schema/pod_type.dart +++ b/oas/schema/pod_type.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// An enumeration of the available pod types. final schemaPodType = Schema.enumeration( diff --git a/oas/schema/query_request.dart b/oas/schema/query_request.dart index 1962e38..83783cb 100644 --- a/oas/schema/query_request.dart +++ b/oas/schema/query_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector query request object final schemaQueryRequest = Schema.object( diff --git a/oas/schema/query_response.dart b/oas/schema/query_response.dart index 9b1f4e0..ca98f27 100644 --- a/oas/schema/query_response.dart +++ b/oas/schema/query_response.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector query response object final schemaQueryResponse = Schema.object( diff --git a/oas/schema/search_metric.dart b/oas/schema/search_metric.dart index 3f6f27c..809a0e5 100644 --- a/oas/schema/search_metric.dart +++ b/oas/schema/search_metric.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// An enumeration of the available pod types. final schemaSearchMetric = Schema.enumeration( diff --git a/oas/schema/sparse_vector.dart b/oas/schema/sparse_vector.dart index 2ec4e5b..214ff63 100644 --- a/oas/schema/sparse_vector.dart +++ b/oas/schema/sparse_vector.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Sparse values object final schemaSparseVector = Schema.object( diff --git a/oas/schema/update_request.dart b/oas/schema/update_request.dart index a23cb37..d2fbd1a 100644 --- a/oas/schema/update_request.dart +++ b/oas/schema/update_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector fetch request object final schemaUpdateRequest = Schema.object( diff --git a/oas/schema/upsert_request.dart b/oas/schema/upsert_request.dart index 0a9417e..9cd6612 100644 --- a/oas/schema/upsert_request.dart +++ b/oas/schema/upsert_request.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector fetch request object final schemaUpsertRequest = Schema.object( diff --git a/oas/schema/upsert_response.dart b/oas/schema/upsert_response.dart index 10d2fab..1d9be34 100644 --- a/oas/schema/upsert_response.dart +++ b/oas/schema/upsert_response.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector query response object final schemaUpsertResponse = Schema.object( diff --git a/oas/schema/vector.dart b/oas/schema/vector.dart index f915fd5..96a63b0 100644 --- a/oas/schema/vector.dart +++ b/oas/schema/vector.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector identifier final vectorId = Schema.string( diff --git a/oas/schema/vector_match.dart b/oas/schema/vector_match.dart index 0a0c993..5d93fce 100644 --- a/oas/schema/vector_match.dart +++ b/oas/schema/vector_match.dart @@ -1,4 +1,4 @@ -part of pinecone_schema; +part of 'schema.dart'; /// Vector match object final schemaVectorMatch = Schema.object( diff --git a/oas/vector_api/delete.dart b/oas/vector_api/delete.dart index 4e052ec..ec72d4e 100644 --- a/oas/vector_api/delete.dart +++ b/oas/vector_api/delete.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Delete vectors operation final deleteVectors = Operation( diff --git a/oas/vector_api/describe.dart b/oas/vector_api/describe.dart index ecc8c86..3e9226e 100644 --- a/oas/vector_api/describe.dart +++ b/oas/vector_api/describe.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Describe index state operation final describeIndexStats = Operation( diff --git a/oas/vector_api/fetch.dart b/oas/vector_api/fetch.dart index 638ffa9..9d383b1 100644 --- a/oas/vector_api/fetch.dart +++ b/oas/vector_api/fetch.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Fetch vectors operation final fetchVectors = Operation( diff --git a/oas/vector_api/query.dart b/oas/vector_api/query.dart index 7fad3f3..55e4c71 100644 --- a/oas/vector_api/query.dart +++ b/oas/vector_api/query.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Query vectors operation final queryVectors = Operation( diff --git a/oas/vector_api/update.dart b/oas/vector_api/update.dart index 0913f1b..5eea49d 100644 --- a/oas/vector_api/update.dart +++ b/oas/vector_api/update.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Update vectors operation final updateVector = Operation( diff --git a/oas/vector_api/upsert.dart b/oas/vector_api/upsert.dart index 7eb49e1..9ce8b19 100644 --- a/oas/vector_api/upsert.dart +++ b/oas/vector_api/upsert.dart @@ -1,4 +1,4 @@ -part of pinecone_vector_api; +part of 'api.dart'; /// Upsert vectors operation final upsertVectors = Operation( diff --git a/pubspec.yaml b/pubspec.yaml index 287a8e9..d1e6891 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,9 +16,9 @@ dependencies: json_annotation: ^4.8.1 dev_dependencies: - openapi_spec: ^0.5.13 + openapi_spec: ^0.6.0 build_runner: ^2.4.6 - lints: ^2.1.1 + lints: ^3.0.0 freezed: ^2.4.5 json_serializable: ^6.7.1 test: ^1.24.7