This commit is contained in:
2025-07-28 17:07:24 +00:00
parent 18d8ab0278
commit ea54a8aeda
2 changed files with 27 additions and 9 deletions

View File

@@ -1,15 +1,33 @@
import * as smartenv from '@push.rocks/smartenv';
let usedImplementation: typeof import('../core_base/index.js');
// Re-export base types that are common to all implementations
export * from '../core_base/types.js';
// Define the implementation interface
interface IImplementation {
CoreRequest: any;
CoreResponse: any;
isUnixSocket?: (url: string) => boolean;
parseUnixSocketUrl?: (url: string) => { socketPath: string; path: string };
// Type exports
ICoreRequestOptions?: any;
ICoreResponse?: any;
IExtendedIncomingMessage?: any;
}
let usedImplementation: IImplementation;
const smartenvInstance = new smartenv.Smartenv();
export const getImplementation = async () => {
// Initialize the implementation based on environment
const initPromise = (async () => {
if (smartenvInstance.isNode) {
usedImplementation = await smartenvInstance.getSafeNodeModule<
typeof import('../core_node/index.js')
>('../core_node/index.js');
const nodeImpl = await smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
usedImplementation = nodeImpl as IImplementation;
} else {
usedImplementation = await import('../core_fetch/index.js');
const fetchImpl = await import('../core_fetch/index.js');
usedImplementation = fetchImpl as IImplementation;
}
};
})();
// Export a function to ensure implementation is loaded
export const ensureImplementationLoaded = () => initPromise;

View File

@@ -27,9 +27,9 @@ export abstract class CoreRequest<TOptions extends types.IAbstractRequestOptions
protected url: string;
protected options: TOptions;
constructor(url: string, options: TOptions) {
constructor(url: string, options?: TOptions) {
this.url = url;
this.options = options;
this.options = options || ({} as TOptions);
}
/**