fix(client): Fix CI configuration, prevent socket hangs with auto-drain, and apply various client/core TypeScript fixes and test updates
This commit is contained in:
@@ -5,13 +5,18 @@ import { CoreRequest as AbstractCoreRequest } from '../core_base/request.js';
|
||||
/**
|
||||
* Fetch-based implementation of Core Request class
|
||||
*/
|
||||
export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions, CoreResponse> {
|
||||
export class CoreRequest extends AbstractCoreRequest<
|
||||
types.ICoreRequestOptions,
|
||||
CoreResponse
|
||||
> {
|
||||
constructor(url: string, options: types.ICoreRequestOptions = {}) {
|
||||
super(url, options);
|
||||
|
||||
|
||||
// Check for unsupported Node.js-specific options
|
||||
if (options.agent || options.socketPath) {
|
||||
throw new Error('Node.js specific options (agent, socketPath) are not supported in browser/fetch implementation');
|
||||
throw new Error(
|
||||
'Node.js specific options (agent, socketPath) are not supported in browser/fetch implementation',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +24,10 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
* Build the full URL with query parameters
|
||||
*/
|
||||
private buildUrl(): string {
|
||||
if (!this.options.queryParams || Object.keys(this.options.queryParams).length === 0) {
|
||||
if (
|
||||
!this.options.queryParams ||
|
||||
Object.keys(this.options.queryParams).length === 0
|
||||
) {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
@@ -50,11 +58,13 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
|
||||
// Handle request body
|
||||
if (this.options.requestBody !== undefined) {
|
||||
if (typeof this.options.requestBody === 'string' ||
|
||||
this.options.requestBody instanceof ArrayBuffer ||
|
||||
this.options.requestBody instanceof FormData ||
|
||||
this.options.requestBody instanceof URLSearchParams ||
|
||||
this.options.requestBody instanceof ReadableStream) {
|
||||
if (
|
||||
typeof this.options.requestBody === 'string' ||
|
||||
this.options.requestBody instanceof ArrayBuffer ||
|
||||
this.options.requestBody instanceof FormData ||
|
||||
this.options.requestBody instanceof URLSearchParams ||
|
||||
this.options.requestBody instanceof ReadableStream
|
||||
) {
|
||||
fetchOptions.body = this.options.requestBody;
|
||||
} else {
|
||||
// Convert objects to JSON
|
||||
@@ -66,7 +76,10 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
if (!fetchOptions.headers.has('Content-Type')) {
|
||||
fetchOptions.headers.set('Content-Type', 'application/json');
|
||||
}
|
||||
} else if (typeof fetchOptions.headers === 'object' && !Array.isArray(fetchOptions.headers)) {
|
||||
} else if (
|
||||
typeof fetchOptions.headers === 'object' &&
|
||||
!Array.isArray(fetchOptions.headers)
|
||||
) {
|
||||
const headersObj = fetchOptions.headers as Record<string, string>;
|
||||
if (!headersObj['Content-Type']) {
|
||||
headersObj['Content-Type'] = 'application/json';
|
||||
@@ -77,7 +90,8 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
|
||||
// Handle timeout
|
||||
if (this.options.timeout || this.options.hardDataCuttingTimeout) {
|
||||
const timeout = this.options.hardDataCuttingTimeout || this.options.timeout;
|
||||
const timeout =
|
||||
this.options.hardDataCuttingTimeout || this.options.timeout;
|
||||
const controller = new AbortController();
|
||||
setTimeout(() => controller.abort(), timeout);
|
||||
fetchOptions.signal = controller.signal;
|
||||
@@ -100,7 +114,7 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
async fireCore(): Promise<Response> {
|
||||
const url = this.buildUrl();
|
||||
const options = this.buildFetchOptions();
|
||||
|
||||
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
return response;
|
||||
@@ -117,7 +131,7 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
*/
|
||||
static async create(
|
||||
url: string,
|
||||
options: types.ICoreRequestOptions = {}
|
||||
options: types.ICoreRequestOptions = {},
|
||||
): Promise<CoreResponse> {
|
||||
const request = new CoreRequest(url, options);
|
||||
return request.fire();
|
||||
@@ -128,4 +142,4 @@ export class CoreRequest extends AbstractCoreRequest<types.ICoreRequestOptions,
|
||||
* Convenience exports for backward compatibility
|
||||
*/
|
||||
export const isUnixSocket = CoreRequest.isUnixSocket;
|
||||
export const parseUnixSocketUrl = CoreRequest.parseUnixSocketUrl;
|
||||
export const parseUnixSocketUrl = CoreRequest.parseUnixSocketUrl;
|
||||
|
Reference in New Issue
Block a user