Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redefine urllib export types #5386

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ site/dist
.umi-production
.vercel
package-lock.json
.tshy*
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
HttpClientResponse as HttpClientResponseOld,
} from 'urllib';
import {
RequestURL as HttpClientRequestURL,
RequestOptions as HttpClientRequestOptions,
HttpClientResponse,
RequestURL,
RequestOptions,
HttpClientResponse as HttpClientResponseNext,
} from 'urllib-next';
import {
EggCoreBase,
Expand Down Expand Up @@ -60,7 +60,9 @@ declare module 'egg' {
// return await app.httpclient.request(url, options);
// }
// ```
export { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse };
export type HttpClientRequestURL = RequestURL;
export type HttpClientRequestOptions = RequestOptions;
export type HttpClientResponse<T = any> = HttpClientResponseNext<T>;
// Compatible with both urllib@2 and urllib@3 RequestOptions to request
export interface EggHttpClient extends EventEmitter {
request<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/apps/app-ts/app/controller/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
EggLogger,
EggHttpClient,
EggContextHttpClient,
HttpClientRequestURL,
HttpClientRequestOptions as RequestOptionsNext,
} from 'egg';
import { RequestOptions as RequestOptionsNext } from 'urllib-next';
import { RequestOptions2, RequestOptions } from 'urllib';

// add user controller and service
Expand Down Expand Up @@ -59,8 +60,8 @@ export default class FooController extends Controller {
}
}

async requestWithHttpclientNext(request: RequestOptionsNext) {
let result = await this.app.curl('url', request);
async requestWithHttpclientNext(request: RequestOptionsNext, url?: HttpClientRequestURL) {
let result = await this.app.curl(url ?? 'url', request);
result = await this.ctx.curl('url', request);
result = await this.app.httpclient.curl('url', request);
result = await this.app.httpclient.request('url', request);
Expand Down
Loading