Skip to content

Commit 82d0903

Browse files
release: 0.9.1 (#142)
Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 0faa765 commit 82d0903

7 files changed

+44
-56
lines changed

.release-please-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.9.0"
2+
".": "0.9.1"
33
}

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-98874226a7dcad763f5fb96534de25a43f9187733a5293fa278b0b61bf71a9b3.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-a711d22c2283945608fc5ab6a399805da8961d6b9e0e068637d389ed611230c0.yml

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.9.1 (2024-12-12)
4+
5+
Full Changelog: [v0.9.0...v0.9.1](https://github.com/groq/groq-typescript/compare/v0.9.0...v0.9.1)
6+
7+
### Chores
8+
9+
* **internal:** remove unnecessary getRequestClient function ([#141](https://github.com/groq/groq-typescript/issues/141)) ([05ccf25](https://github.com/groq/groq-typescript/commit/05ccf251bb1e1bf0afc3af5572f4faf20ebd1410))
10+
* **internal:** update isAbsoluteURL ([#145](https://github.com/groq/groq-typescript/issues/145)) ([18e414e](https://github.com/groq/groq-typescript/commit/18e414ed562876eb1dadff97a79aa2bbe90ff0ab))
11+
* **types:** nicer error class types + jsdocs ([#144](https://github.com/groq/groq-typescript/issues/144)) ([860655e](https://github.com/groq/groq-typescript/commit/860655eb638047c681ed602002e1de8dfacb7d3d))
12+
313
## 0.9.0 (2024-12-03)
414

515
Full Changelog: [v0.8.0...v0.9.0](https://github.com/groq/groq-typescript/compare/v0.8.0...v0.9.0)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "groq-sdk",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"description": "The official TypeScript library for the Groq API",
55
"author": "Groq <[email protected]>",
66
"types": "dist/index.d.ts",

src/core.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -537,19 +537,13 @@ export abstract class APIClient {
537537
const timeout = setTimeout(() => controller.abort(), ms);
538538

539539
return (
540-
this.getRequestClient()
541-
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
542-
.fetch.call(undefined, url, { signal: controller.signal as any, ...options })
543-
.finally(() => {
544-
clearTimeout(timeout);
545-
})
540+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
541+
this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
542+
clearTimeout(timeout);
543+
})
546544
);
547545
}
548546

549-
protected getRequestClient(): RequestClient {
550-
return { fetch: this.fetch };
551-
}
552-
553547
private shouldRetry(response: Response): boolean {
554548
// Note this is not a standard header.
555549
const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -992,8 +986,8 @@ export const safeJSON = (text: string) => {
992986
}
993987
};
994988

995-
// https://stackoverflow.com/a/19709846
996-
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
989+
// https://url.spec.whatwg.org/#url-scheme-string
990+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
997991
const isAbsoluteURL = (url: string): boolean => {
998992
return startsWithSchemeRegexp.test(url);
999993
};

src/error.ts

+24-40
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import { castToError, Headers } from './core';
44

55
export class GroqError extends Error {}
66

7-
export class APIError extends GroqError {
8-
readonly status: number | undefined;
9-
readonly headers: Headers | undefined;
10-
readonly error: Object | undefined;
11-
12-
constructor(
13-
status: number | undefined,
14-
error: Object | undefined,
15-
message: string | undefined,
16-
headers: Headers | undefined,
17-
) {
7+
export class APIError<
8+
TStatus extends number | undefined = number | undefined,
9+
THeaders extends Headers | undefined = Headers | undefined,
10+
TError extends Object | undefined = Object | undefined,
11+
> extends GroqError {
12+
/** HTTP status for the response that caused the error */
13+
readonly status: TStatus;
14+
/** HTTP headers for the response that caused the error */
15+
readonly headers: THeaders;
16+
/** JSON body of the response that caused the error */
17+
readonly error: TError;
18+
19+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
1820
super(`${APIError.makeMessage(status, error, message)}`);
1921
this.status = status;
2022
this.headers = headers;
@@ -48,7 +50,7 @@ export class APIError extends GroqError {
4850
message: string | undefined,
4951
headers: Headers | undefined,
5052
): APIError {
51-
if (!status) {
53+
if (!status || !headers) {
5254
return new APIConnectionError({ message, cause: castToError(errorResponse) });
5355
}
5456

@@ -90,17 +92,13 @@ export class APIError extends GroqError {
9092
}
9193
}
9294

93-
export class APIUserAbortError extends APIError {
94-
override readonly status: undefined = undefined;
95-
95+
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
9696
constructor({ message }: { message?: string } = {}) {
9797
super(undefined, undefined, message || 'Request was aborted.', undefined);
9898
}
9999
}
100100

101-
export class APIConnectionError extends APIError {
102-
override readonly status: undefined = undefined;
103-
101+
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
104102
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
105103
super(undefined, undefined, message || 'Connection error.', undefined);
106104
// in some environments the 'cause' property is already declared
@@ -115,32 +113,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
115113
}
116114
}
117115

118-
export class BadRequestError extends APIError {
119-
override readonly status: 400 = 400;
120-
}
116+
export class BadRequestError extends APIError<400, Headers> {}
121117

122-
export class AuthenticationError extends APIError {
123-
override readonly status: 401 = 401;
124-
}
118+
export class AuthenticationError extends APIError<401, Headers> {}
125119

126-
export class PermissionDeniedError extends APIError {
127-
override readonly status: 403 = 403;
128-
}
120+
export class PermissionDeniedError extends APIError<403, Headers> {}
129121

130-
export class NotFoundError extends APIError {
131-
override readonly status: 404 = 404;
132-
}
122+
export class NotFoundError extends APIError<404, Headers> {}
133123

134-
export class ConflictError extends APIError {
135-
override readonly status: 409 = 409;
136-
}
124+
export class ConflictError extends APIError<409, Headers> {}
137125

138-
export class UnprocessableEntityError extends APIError {
139-
override readonly status: 422 = 422;
140-
}
126+
export class UnprocessableEntityError extends APIError<422, Headers> {}
141127

142-
export class RateLimitError extends APIError {
143-
override readonly status: 429 = 429;
144-
}
128+
export class RateLimitError extends APIError<429, Headers> {}
145129

146-
export class InternalServerError extends APIError {}
130+
export class InternalServerError extends APIError<number, Headers> {}

src/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '0.9.0'; // x-release-please-version
1+
export const VERSION = '0.9.1'; // x-release-please-version

0 commit comments

Comments
 (0)