Files
smartrequest/ts/core/index.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-07-28 17:01:34 +00:00
import * as smartenv from '@push.rocks/smartenv';
2025-07-28 17:07:24 +00:00
// Re-export base types that are common to all implementations
export * from '../core_base/types.js';
2025-07-28 17:01:34 +00:00
2025-07-28 17:07:24 +00:00
// 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;
2025-07-28 17:01:34 +00:00
const smartenvInstance = new smartenv.Smartenv();
2025-07-28 17:07:24 +00:00
// Initialize the implementation based on environment
const initPromise = (async () => {
2025-07-28 17:01:34 +00:00
if (smartenvInstance.isNode) {
2025-07-28 17:07:24 +00:00
const nodeImpl = await smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
usedImplementation = nodeImpl as IImplementation;
2025-07-28 17:01:34 +00:00
} else {
2025-07-28 17:07:24 +00:00
const fetchImpl = await import('../core_fetch/index.js');
usedImplementation = fetchImpl as IImplementation;
2025-07-28 17:01:34 +00:00
}
2025-07-28 17:07:24 +00:00
})();
// Export a function to ensure implementation is loaded
export const ensureImplementationLoaded = () => initPromise;