update
This commit is contained in:
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user