This commit is contained in:
2025-07-28 17:23:48 +00:00
parent 94bf23ad55
commit bc99aa3569
10 changed files with 19 additions and 321 deletions

View File

@@ -1,33 +1,22 @@
import * as smartenv from '@push.rocks/smartenv';
// Re-export base types that are common to all implementations
// Export all base types - these are the public API
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();
// Initialize the implementation based on environment
const initPromise = (async () => {
// Load the appropriate implementation based on environment
const implementation = await (async () => {
if (smartenvInstance.isNode) {
const nodeImpl = await smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
usedImplementation = nodeImpl as IImplementation;
return smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
} else {
const fetchImpl = await import('../core_fetch/index.js');
usedImplementation = fetchImpl as IImplementation;
return import('../core_fetch/index.js');
}
})();
// Export a function to ensure implementation is loaded
export const ensureImplementationLoaded = () => initPromise;
// Export the implementation classes
export const CoreRequest = implementation.CoreRequest;
export const CoreResponse = implementation.CoreResponse;
// Export CoreResponse as a type for type annotations
export type CoreResponse<T = any> = InstanceType<typeof implementation.CoreResponse>;