Skip to content

Commit

Permalink
Bump to v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
walsha2 committed Nov 13, 2023
1 parent ab2d1e1 commit f82039c
Show file tree
Hide file tree
Showing 22 changed files with 721 additions and 367 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.7.0

* Client generation using latest `openapi_spec` package (v0.7.6)
* Breaking: `PodType` enum values are now camel case

## 0.6.0

* Client generation using latest `openapi_spec` package (v0.6.0)
Expand Down
158 changes: 115 additions & 43 deletions lib/src/generated/client.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import

import 'dart:io' as io;
import 'dart:convert';
import 'dart:io' as io;
import 'dart:typed_data';

import 'package:http/http.dart' as http;
import 'package:http/retry.dart';
import 'package:meta/meta.dart';

import 'schema/schema.dart';

/// Enum of HTTP methods
Expand All @@ -25,6 +29,7 @@ class PineconeClientException implements io.HttpException {
this.code,
this.body,
});

@override
final String message;
@override
Expand Down Expand Up @@ -56,31 +61,38 @@ class PineconeClientException implements io.HttpException {
// CLASS: PineconeClient
// ==========================================

/// Client for Pinecone API
///
/// `baseUrl`: Override baseUrl URL - else defaults to server url defined in spec
/// Client for Pinecone API (v.1.1.0)
///
/// `client`: Override HTTP client to use for requests
/// No description
class PineconeClient {
/// Creates a new PineconeClient instance.
///
/// - [PineconeClient.baseUrl] Override base URL (default: server url defined in spec)
/// - [PineconeClient.headers] Global headers to be sent with every request
/// - [PineconeClient.client] Override HTTP client to use for requests
PineconeClient({
this.apiKey = '',
String? baseUrl,
this.baseUrl,
this.headers = const {},
http.Client? client,
}) : assert(
}) : 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());
}
),
assert(
baseUrl == null || !baseUrl.endsWith('/'),
'baseUrl must not end with /',
),
client = RetryClient(client ?? http.Client());

/// Override base URL (default: server url defined in spec)
final String? baseUrl;

/// User provided override for baseUrl URL
late final String? baseUrl;
/// Global headers to be sent with every request
final Map<String, String> headers;

/// HTTP client for requests
late final http.Client client;
final http.Client client;

/// Authentication related variables
final String apiKey;
Expand All @@ -99,25 +111,37 @@ class PineconeClient {
/// Middleware for HTTP requests (user can override)
///
/// The request can be of type [http.Request] or [http.MultipartRequest]
Future<http.BaseRequest> onRequest(http.BaseRequest request) async {
return request;
Future<http.BaseRequest> onRequest(http.BaseRequest request) {
return Future.value(request);
}

// ------------------------------------------
// METHOD: onStreamedResponse
// ------------------------------------------

/// Middleware for HTTP streamed responses (user can override)
Future<http.StreamedResponse> onStreamedResponse(
final http.StreamedResponse response,
) {
return Future.value(response);
}

// ------------------------------------------
// METHOD: onResponse
// ------------------------------------------

/// Middleware for HTTP responses (user can override)
Future<http.Response> onResponse(http.Response response) async {
return response;
Future<http.Response> onResponse(http.Response response) {
return Future.value(response);
}

// ------------------------------------------
// METHOD: _request
// METHOD: makeRequestStream
// ------------------------------------------

/// Reusable request method
Future<http.Response> _request({
/// Reusable request stream method
@protected
Future<http.StreamedResponse> makeRequestStream({
required String baseUrl,
required String path,
required HttpMethod method,
Expand Down Expand Up @@ -165,8 +189,11 @@ class PineconeClient {
headers['accept'] = responseType;
}

// Add global headers
headers.addAll(this.headers);

// Build the request object
late http.Response response;
late http.StreamedResponse response;
try {
http.BaseRequest request;
if (isMultipart) {
Expand Down Expand Up @@ -204,10 +231,10 @@ class PineconeClient {
request = await onRequest(request);

// Submit request
response = await http.Response.fromStream(await client.send(request));
response = await client.send(request);

// Handle user response middleware
response = await onResponse(response);
response = await onStreamedResponse(response);
} catch (e) {
// Handle request and response errors
throw PineconeClientException(
Expand All @@ -229,10 +256,55 @@ class PineconeClient {
method: method,
message: 'Unsuccessful response',
code: response.statusCode,
body: response.body,
body: (await http.Response.fromStream(response)).body,
);
}

// ------------------------------------------
// METHOD: makeRequest
// ------------------------------------------

/// Reusable request method
@protected
Future<http.Response> makeRequest({
required String baseUrl,
required String path,
required HttpMethod method,
Map<String, dynamic> queryParams = const {},
Map<String, String> headerParams = const {},
bool isMultipart = false,
String requestType = '',
String responseType = '',
Object? body,
}) async {
try {
final streamedResponse = await makeRequestStream(
baseUrl: baseUrl,
path: path,
method: method,
queryParams: queryParams,
headerParams: headerParams,
requestType: requestType,
responseType: responseType,
body: body,
);
final response = await http.Response.fromStream(streamedResponse);

// Handle user response middleware
return await onResponse(response);
} on PineconeClientException {
rethrow;
} catch (e) {
// Handle request and response errors
throw PineconeClientException(
uri: Uri.parse((this.baseUrl ?? baseUrl) + path),
method: method,
message: 'Response error',
body: e,
);
}
}

// ------------------------------------------
// METHOD: listCollections
// ------------------------------------------
Expand All @@ -247,7 +319,7 @@ class PineconeClient {
Future<List<String>> listCollections({
String environment = 'us-west1-gcp-free',
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections',
method: HttpMethod.get,
Expand Down Expand Up @@ -278,7 +350,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required CreateCollectionRequest request,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections',
method: HttpMethod.post,
Expand Down Expand Up @@ -309,7 +381,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required String collectionName,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections/$collectionName',
method: HttpMethod.get,
Expand Down Expand Up @@ -340,7 +412,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required String collectionName,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections/$collectionName',
method: HttpMethod.delete,
Expand All @@ -367,7 +439,7 @@ class PineconeClient {
Future<List<String>> listIndexes({
String environment = 'us-west1-gcp-free',
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases',
method: HttpMethod.get,
Expand Down Expand Up @@ -398,7 +470,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required CreateIndexRequest request,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases',
method: HttpMethod.post,
Expand Down Expand Up @@ -429,7 +501,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required String indexName,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.get,
Expand Down Expand Up @@ -460,7 +532,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
required String indexName,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.delete,
Expand Down Expand Up @@ -493,7 +565,7 @@ class PineconeClient {
required String indexName,
required ConfigureIndexRequest request,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.patch,
Expand Down Expand Up @@ -530,7 +602,7 @@ class PineconeClient {
required String environment,
IndexStatsRequest? request,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/describe_index_stats',
Expand Down Expand Up @@ -569,7 +641,7 @@ class PineconeClient {
required String environment,
required QueryRequest request,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/query',
Expand Down Expand Up @@ -608,7 +680,7 @@ class PineconeClient {
required String environment,
required DeleteRequest request,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/delete',
Expand Down Expand Up @@ -649,7 +721,7 @@ class PineconeClient {
required List<String> ids,
String? namespace,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/fetch',
Expand Down Expand Up @@ -691,7 +763,7 @@ class PineconeClient {
required String environment,
required UpdateRequest request,
}) async {
final _ = await _request(
final _ = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/update',
Expand Down Expand Up @@ -729,7 +801,7 @@ class PineconeClient {
required String environment,
required UpsertRequest request,
}) async {
final r = await _request(
final r = await makeRequest(
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/upsert',
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generated/schema/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Collection with _$Collection {
required CollectionStatus status,

/// The size of the collection in bytes.
int? size,
@JsonKey(includeIfNull: false) int? size,

/// The dimensionality of the collection.
required int dimension,
Expand Down
1 change: 1 addition & 0 deletions lib/src/generated/schema/configure_index_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ConfigureIndexRequest with _$ConfigureIndexRequest {
/// An enumeration of the available pod types.
@JsonKey(
name: 'pod_type',
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
PodType? podType,
Expand Down
8 changes: 5 additions & 3 deletions lib/src/generated/schema/create_index_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class CreateIndexRequest with _$CreateIndexRequest {
@Default(1) int replicas,

/// An enumeration of the available pod types.
@JsonKey(name: 'pod_type') @Default(PodType.p1x1) PodType podType,
@JsonKey(name: 'pod_type') @Default(PodType.p1X1) PodType podType,

/// Configuration for the behavior of Pinecone's internal metadata index.
@JsonKey(name: 'metadata_config') Map<String, dynamic>? metadataConfig,
@JsonKey(name: 'metadata_config', includeIfNull: false)
Map<String, dynamic>? metadataConfig,

/// The name of the collection to create an index from.
@JsonKey(name: 'source_collection') String? sourceCollection,
@JsonKey(name: 'source_collection', includeIfNull: false)
String? sourceCollection,
}) = _CreateIndexRequest;

/// Object construction from a JSON representation
Expand Down
Loading

0 comments on commit f82039c

Please sign in to comment.