Files
smartrequest/ts/core/index.ts

40 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-07-28 22:37:36 +00:00
import * as plugins from './plugins.js';
2025-07-28 17:01:34 +00:00
2025-07-28 17:23:48 +00:00
// Export all base types - these are the public API
2025-07-28 17:07:24 +00:00
export * from '../core_base/types.js';
2025-07-28 17:01:34 +00:00
2025-07-28 22:37:36 +00:00
const smartenvInstance = new plugins.smartenv.Smartenv();
2025-07-28 17:01:34 +00:00
// Dynamically load the appropriate implementation based on runtime
2025-07-28 22:37:36 +00:00
let CoreRequest: any;
let CoreResponse: any;
2025-07-28 17:07:24 +00:00
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
2025-07-28 22:37:36 +00:00
const modulePath = plugins.smartpath.join(
plugins.smartpath.dirname(import.meta.url),
'../core_node/index.js',
);
2025-07-28 22:37:36 +00:00
const impl = await smartenvInstance.getSafeNodeModule(modulePath);
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
} else {
// In browser, load the fetch implementation (no unix socket support)
2025-07-28 22:37:36 +00:00
const impl = await import('../core_fetch/index.js');
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
}
2025-07-28 17:23:48 +00:00
2025-07-28 22:37:36 +00:00
// Export the loaded implementations
export { CoreRequest, CoreResponse };