Files
smartrequest/ts/core/index.ts

40 lines
1.4 KiB
TypeScript

import * as plugins from './plugins.js';
// Export all base types - these are the public API
export * from '../core_base/types.js';
const smartenvInstance = new plugins.smartenv.Smartenv();
// Dynamically load the appropriate implementation based on runtime
let CoreRequest: any;
let CoreResponse: any;
if (smartenvInstance.isDeno) {
// In Deno, load the Deno implementation with HttpClient-based unix socket support
const impl = await import('../core_deno/index.js');
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
} else if (smartenvInstance.isBun) {
// In Bun, load the Bun implementation with native fetch unix socket support
const impl = await import('../core_bun/index.js');
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
} else if (smartenvInstance.isNode) {
// In Node.js, load the Node.js implementation with native http/https unix socket support
const modulePath = plugins.smartpath.join(
plugins.smartpath.dirname(import.meta.url),
'../core_node/index.js',
);
const impl = await smartenvInstance.getSafeNodeModule(modulePath);
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
} else {
// In browser, load the fetch implementation (no unix socket support)
const impl = await import('../core_fetch/index.js');
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
}
// Export the loaded implementations
export { CoreRequest, CoreResponse };