Files
smartrequest/ts/core/index.ts

31 lines
919 B
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
let CoreRequest: any;
let CoreResponse: any;
if (smartenvInstance.isNode) {
// In Node.js, load the node implementation
const modulePath = plugins.smartpath.join(
plugins.smartpath.dirname(import.meta.url),
'../core_node/index.js',
);
console.log(modulePath);
const impl = await smartenvInstance.getSafeNodeModule(modulePath);
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
} else {
// In browser, load the fetch implementation
const impl = await import('../core_fetch/index.js');
CoreRequest = impl.CoreRequest;
CoreResponse = impl.CoreResponse;
}
// Export the loaded implementations
export { CoreRequest, CoreResponse };