Skip to content

Commit 1eb5887

Browse files
committed
Bump to v0.7.2
1 parent 81fd039 commit 1eb5887

File tree

3 files changed

+117
-58
lines changed

3 files changed

+117
-58
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.7.2
4+
5+
* Client generation using latest `openapi_spec` package (v0.7.8)
6+
37
## 0.7.1
48

59
* Relax `meta` version requirement

lib/src/generated/client.dart

Lines changed: 110 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// ignore_for_file: invalid_annotation_target, unused_import
55

66
import 'dart:convert';
7-
import 'dart:io' as io;
87
import 'dart:typed_data';
98

109
import 'package:http/http.dart' as http;
@@ -21,7 +20,7 @@ enum HttpMethod { get, put, post, delete, options, head, patch, trace }
2120
// ==========================================
2221

2322
/// HTTP exception handler for PineconeClient
24-
class PineconeClientException implements io.HttpException {
23+
class PineconeClientException implements Exception {
2524
PineconeClientException({
2625
required this.message,
2726
required this.uri,
@@ -30,9 +29,7 @@ class PineconeClientException implements io.HttpException {
3029
this.body,
3130
});
3231

33-
@override
3432
final String message;
35-
@override
3633
final Uri uri;
3734
final HttpMethod method;
3835
final int? code;
@@ -69,11 +66,13 @@ class PineconeClient {
6966
///
7067
/// - [PineconeClient.baseUrl] Override base URL (default: server url defined in spec)
7168
/// - [PineconeClient.headers] Global headers to be sent with every request
69+
/// - [PineconeClient.queryParams] Global query parameters to be sent with every request
7270
/// - [PineconeClient.client] Override HTTP client to use for requests
7371
PineconeClient({
7472
this.apiKey = '',
7573
this.baseUrl,
7674
this.headers = const {},
75+
this.queryParams = const {},
7776
http.Client? client,
7877
}) : assert(
7978
baseUrl == null || baseUrl.startsWith('http'),
@@ -91,6 +90,9 @@ class PineconeClient {
9190
/// Global headers to be sent with every request
9291
final Map<String, String> headers;
9392

93+
/// Global query parameters to be sent with every request
94+
final Map<String, dynamic> queryParams;
95+
9496
/// HTTP client for requests
9597
final http.Client client;
9698

@@ -136,12 +138,20 @@ class PineconeClient {
136138
}
137139

138140
// ------------------------------------------
139-
// METHOD: makeRequestStream
141+
// METHOD: _jsonDecode
140142
// ------------------------------------------
141143

142-
/// Reusable request stream method
144+
dynamic _jsonDecode(http.Response r) {
145+
return json.decode(utf8.decode(r.bodyBytes));
146+
}
147+
148+
// ------------------------------------------
149+
// METHOD: _request
150+
// ------------------------------------------
151+
152+
/// Reusable request method
143153
@protected
144-
Future<http.StreamedResponse> makeRequestStream({
154+
Future<http.StreamedResponse> _request({
145155
required String baseUrl,
146156
required String path,
147157
required HttpMethod method,
@@ -161,6 +171,9 @@ class PineconeClient {
161171
'baseUrl is required, but none defined in spec or provided by user',
162172
);
163173

174+
// Add global query parameters
175+
queryParams = {...queryParams, ...this.queryParams};
176+
164177
// Ensure query parameters are strings or iterable of strings
165178
queryParams = queryParams.map((key, value) {
166179
if (value is Iterable) {
@@ -193,46 +206,75 @@ class PineconeClient {
193206
headers.addAll(this.headers);
194207

195208
// Build the request object
196-
late http.StreamedResponse response;
197-
try {
198-
http.BaseRequest request;
199-
if (isMultipart) {
200-
// Handle multipart request
201-
request = http.MultipartRequest(method.name, uri);
202-
request = request as http.MultipartRequest;
203-
if (body is List<http.MultipartFile>) {
204-
request.files.addAll(body);
205-
} else {
206-
request.files.add(body as http.MultipartFile);
207-
}
209+
http.BaseRequest request;
210+
if (isMultipart) {
211+
// Handle multipart request
212+
request = http.MultipartRequest(method.name, uri);
213+
request = request as http.MultipartRequest;
214+
if (body is List<http.MultipartFile>) {
215+
request.files.addAll(body);
208216
} else {
209-
// Handle normal request
210-
request = http.Request(method.name, uri);
211-
request = request as http.Request;
212-
try {
213-
if (body != null) {
214-
request.body = json.encode(body);
215-
}
216-
} catch (e) {
217-
// Handle request encoding error
218-
throw PineconeClientException(
219-
uri: uri,
220-
method: method,
221-
message: 'Could not encode: ${body.runtimeType}',
222-
body: e,
223-
);
217+
request.files.add(body as http.MultipartFile);
218+
}
219+
} else {
220+
// Handle normal request
221+
request = http.Request(method.name, uri);
222+
request = request as http.Request;
223+
try {
224+
if (body != null) {
225+
request.body = json.encode(body);
224226
}
227+
} catch (e) {
228+
// Handle request encoding error
229+
throw PineconeClientException(
230+
uri: uri,
231+
method: method,
232+
message: 'Could not encode: ${body.runtimeType}',
233+
body: e,
234+
);
225235
}
236+
}
226237

227-
// Add request headers
228-
request.headers.addAll(headers);
238+
// Add request headers
239+
request.headers.addAll(headers);
229240

230-
// Handle user request middleware
231-
request = await onRequest(request);
241+
// Handle user request middleware
242+
request = await onRequest(request);
243+
244+
// Submit request
245+
return await client.send(request);
246+
}
232247

233-
// Submit request
234-
response = await client.send(request);
248+
// ------------------------------------------
249+
// METHOD: makeRequestStream
250+
// ------------------------------------------
235251

252+
/// Reusable request stream method
253+
@protected
254+
Future<http.StreamedResponse> makeRequestStream({
255+
required String baseUrl,
256+
required String path,
257+
required HttpMethod method,
258+
Map<String, dynamic> queryParams = const {},
259+
Map<String, String> headerParams = const {},
260+
bool isMultipart = false,
261+
String requestType = '',
262+
String responseType = '',
263+
Object? body,
264+
}) async {
265+
final uri = Uri.parse((this.baseUrl ?? baseUrl) + path);
266+
late http.StreamedResponse response;
267+
try {
268+
response = await _request(
269+
baseUrl: baseUrl,
270+
path: path,
271+
method: method,
272+
queryParams: queryParams,
273+
headerParams: headerParams,
274+
requestType: requestType,
275+
responseType: responseType,
276+
body: body,
277+
);
236278
// Handle user response middleware
237279
response = await onStreamedResponse(response);
238280
} catch (e) {
@@ -277,8 +319,10 @@ class PineconeClient {
277319
String responseType = '',
278320
Object? body,
279321
}) async {
322+
final uri = Uri.parse((this.baseUrl ?? baseUrl) + path);
323+
late http.Response response;
280324
try {
281-
final streamedResponse = await makeRequestStream(
325+
final streamedResponse = await _request(
282326
baseUrl: baseUrl,
283327
path: path,
284328
method: method,
@@ -288,21 +332,32 @@ class PineconeClient {
288332
responseType: responseType,
289333
body: body,
290334
);
291-
final response = await http.Response.fromStream(streamedResponse);
292-
335+
response = await http.Response.fromStream(streamedResponse);
293336
// Handle user response middleware
294-
return await onResponse(response);
295-
} on PineconeClientException {
296-
rethrow;
337+
response = await onResponse(response);
297338
} catch (e) {
298339
// Handle request and response errors
299340
throw PineconeClientException(
300-
uri: Uri.parse((this.baseUrl ?? baseUrl) + path),
341+
uri: uri,
301342
method: method,
302343
message: 'Response error',
303344
body: e,
304345
);
305346
}
347+
348+
// Check for successful response
349+
if ((response.statusCode ~/ 100) == 2) {
350+
return response;
351+
}
352+
353+
// Handle unsuccessful response
354+
throw PineconeClientException(
355+
uri: uri,
356+
method: method,
357+
message: 'Unsuccessful response',
358+
code: response.statusCode,
359+
body: response.body,
360+
);
306361
}
307362

308363
// ------------------------------------------
@@ -330,7 +385,7 @@ class PineconeClient {
330385
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
331386
},
332387
);
333-
return List<String>.from(json.decode(r.body));
388+
return List<String>.from(_jsonDecode(r));
334389
}
335390

336391
// ------------------------------------------
@@ -392,7 +447,7 @@ class PineconeClient {
392447
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
393448
},
394449
);
395-
return Collection.fromJson(json.decode(r.body));
450+
return Collection.fromJson(_jsonDecode(r));
396451
}
397452

398453
// ------------------------------------------
@@ -450,7 +505,7 @@ class PineconeClient {
450505
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
451506
},
452507
);
453-
return List<String>.from(json.decode(r.body));
508+
return List<String>.from(_jsonDecode(r));
454509
}
455510

456511
// ------------------------------------------
@@ -512,7 +567,7 @@ class PineconeClient {
512567
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
513568
},
514569
);
515-
return Index.fromJson(json.decode(r.body));
570+
return Index.fromJson(_jsonDecode(r));
516571
}
517572

518573
// ------------------------------------------
@@ -615,7 +670,7 @@ class PineconeClient {
615670
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
616671
},
617672
);
618-
return IndexStats.fromJson(json.decode(r.body));
673+
return IndexStats.fromJson(_jsonDecode(r));
619674
}
620675

621676
// ------------------------------------------
@@ -654,7 +709,7 @@ class PineconeClient {
654709
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
655710
},
656711
);
657-
return QueryResponse.fromJson(json.decode(r.body));
712+
return QueryResponse.fromJson(_jsonDecode(r));
658713
}
659714

660715
// ------------------------------------------
@@ -737,7 +792,7 @@ class PineconeClient {
737792
if (namespace != null) 'namespace': namespace,
738793
},
739794
);
740-
return FetchResponse.fromJson(json.decode(r.body));
795+
return FetchResponse.fromJson(_jsonDecode(r));
741796
}
742797

743798
// ------------------------------------------
@@ -814,6 +869,6 @@ class PineconeClient {
814869
if (apiKey.isNotEmpty) 'Api-Key': apiKey,
815870
},
816871
);
817-
return UpsertResponse.fromJson(json.decode(r.body));
872+
return UpsertResponse.fromJson(_jsonDecode(r));
818873
}
819874
}

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: pinecone
22
description: Unofficial Dart client for Pinecone vector database. For more details on Pinecone, please visit https://docs.pinecone.io/docs/overview.
3-
version: 0.7.1
3+
version: 0.7.2
44
maintainer: Taza Technology LLC
55
repository: https://github.com/tazatechnology/pinecone
66
issue_tracker: https://github.com/tazatechnology/pinecone/issues
@@ -17,9 +17,9 @@ dependencies:
1717
meta: ^1.9.1
1818

1919
dev_dependencies:
20-
openapi_spec: 0.7.6
20+
openapi_spec: 0.7.9
2121
build_runner: ^2.4.6
2222
lints: ^3.0.0
2323
freezed: ^2.4.5
2424
json_serializable: ^6.7.1
25-
test: ^1.24.7
25+
test: ^1.24.9

0 commit comments

Comments
 (0)