From ea54a8aeda60542acf3c66f7eba0c34f8283633c Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 28 Jul 2025 17:07:24 +0000 Subject: [PATCH] update --- ts/core/index.ts | 32 +++++++++++++++++++++++++------- ts/core_base/request.ts | 4 ++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ts/core/index.ts b/ts/core/index.ts index 2b16807..dde6cd5 100644 --- a/ts/core/index.ts +++ b/ts/core/index.ts @@ -1,15 +1,33 @@ import * as smartenv from '@push.rocks/smartenv'; -let usedImplementation: typeof import('../core_base/index.js'); +// Re-export base types that are common to all implementations +export * from '../core_base/types.js'; +// 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; const smartenvInstance = new smartenv.Smartenv(); -export const getImplementation = async () => { +// Initialize the implementation based on environment +const initPromise = (async () => { if (smartenvInstance.isNode) { - usedImplementation = await smartenvInstance.getSafeNodeModule< - typeof import('../core_node/index.js') - >('../core_node/index.js'); + const nodeImpl = await smartenvInstance.getSafeNodeModule('../core_node/index.js'); + usedImplementation = nodeImpl as IImplementation; } else { - usedImplementation = await import('../core_fetch/index.js'); + const fetchImpl = await import('../core_fetch/index.js'); + usedImplementation = fetchImpl as IImplementation; } -}; +})(); + +// Export a function to ensure implementation is loaded +export const ensureImplementationLoaded = () => initPromise; diff --git a/ts/core_base/request.ts b/ts/core_base/request.ts index 635a4fb..3df6526 100644 --- a/ts/core_base/request.ts +++ b/ts/core_base/request.ts @@ -27,9 +27,9 @@ export abstract class CoreRequest