Files
smartrequest/ts/core/index.ts
2025-07-28 17:07:24 +00:00

34 lines
1.1 KiB
TypeScript

import * as smartenv from '@push.rocks/smartenv';
// 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();
// Initialize the implementation based on environment
const initPromise = (async () => {
if (smartenvInstance.isNode) {
const nodeImpl = await smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
usedImplementation = nodeImpl as IImplementation;
} else {
const fetchImpl = await import('../core_fetch/index.js');
usedImplementation = fetchImpl as IImplementation;
}
})();
// Export a function to ensure implementation is loaded
export const ensureImplementationLoaded = () => initPromise;