This commit is contained in:
2025-07-28 22:37:36 +00:00
parent bc99aa3569
commit eb2ccd8d9f
21 changed files with 228 additions and 99 deletions

View File

@@ -1,22 +1,30 @@
import * as smartenv from '@push.rocks/smartenv';
import * as plugins from './plugins.js';
// Export all base types - these are the public API
export * from '../core_base/types.js';
const smartenvInstance = new smartenv.Smartenv();
const smartenvInstance = new plugins.smartenv.Smartenv();
// Load the appropriate implementation based on environment
const implementation = await (async () => {
if (smartenvInstance.isNode) {
return smartenvInstance.getSafeNodeModule<typeof import('../core_node/index.js')>('../core_node/index.js');
} else {
return import('../core_fetch/index.js');
}
})();
// Dynamically load the appropriate implementation
let CoreRequest: any;
let CoreResponse: any;
// Export the implementation classes
export const CoreRequest = implementation.CoreRequest;
export const CoreResponse = implementation.CoreResponse;
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 CoreResponse as a type for type annotations
export type CoreResponse<T = any> = InstanceType<typeof implementation.CoreResponse>;
// Export the loaded implementations
export { CoreRequest, CoreResponse };