Modified middleware typing so that it should be easier to use
Some checks failed
Build, Test, and Publish (to Private NPM Registry) UI Components Library / publish (push) Failing after 56s

This commit is contained in:
Alan Bridgeman 2026-05-13 15:17:35 -05:00
parent 8f0c91a74a
commit 1156a28de4
2 changed files with 5 additions and 5 deletions

View file

@ -166,7 +166,7 @@ async function initializeBAComponentsManualCopy(assets: { url: string | { script
* @param options - An object containing the initialization options. * @param options - An object containing the initialization options.
* @returns A promise that resolves to either an Express middleware function or an object containing the library paths and render function. * @returns A promise that resolves to either an Express middleware function or an object containing the library paths and render function.
*/ */
export default async function initializeBAComponents(options: { expressApp?: Application, assets?: { url: string | { script: string, style: string }, file: string | { script: string, style: string } } } = {}): Promise<RequestHandler | { paths: typeof libraryPaths; render: typeof coreRenderUI }> { export default async function initializeBAComponents<T extends RequestHandler | { paths: typeof libraryPaths; render: typeof coreRenderUI }>(options: { expressApp?: Application, assets?: { url: string | { script: string, style: string }, file: string | { script: string, style: string } } } = {}): Promise<T> {
// Guard against "Both" // Guard against "Both"
if( if(
( (
@ -183,16 +183,16 @@ export default async function initializeBAComponents(options: { expressApp?: App
// --- STRATEGY A: Express Virtual Path --- // --- STRATEGY A: Express Virtual Path ---
if(typeof options.expressApp !== 'undefined') { if(typeof options.expressApp !== 'undefined') {
return await initializeBAComponentsExpressVirtualPath(options.expressApp); return await initializeBAComponentsExpressVirtualPath(options.expressApp) as T;
} }
// --- STRATEGY B: Manual Copy Strategy --- // --- STRATEGY B: Manual Copy Strategy ---
if(typeof options.assets === 'object' && options.assets !== null && typeof options.assets.url !== 'undefined' && typeof options.assets.file !== 'undefined') { if(typeof options.assets === 'object' && options.assets !== null && typeof options.assets.url !== 'undefined' && typeof options.assets.file !== 'undefined') {
return await initializeBAComponentsManualCopy(options.assets); return await initializeBAComponentsManualCopy(options.assets) as T;
} }
// --- STRATEGY C: "Neither" (Framework Agnostic) --- // --- STRATEGY C: "Neither" (Framework Agnostic) ---
// If no options are provided, just return the raw tools. // If no options are provided, just return the raw tools.
// A Fastify or Koa user can use these to build their own integration. // A Fastify or Koa user can use these to build their own integration.
return { paths: libraryPaths, render: coreRenderUI }; return { paths: libraryPaths, render: coreRenderUI } as T;
}; };

View file

@ -7,7 +7,7 @@ app.set('view engine', 'ejs');
app.set('views', './test-harness/views'); app.set('views', './test-harness/views');
// Mount the library using your virtual path strategy // Mount the library using your virtual path strategy
app.use(await baWebComponents({ expressApp: app }) as RequestHandler); app.use(await baWebComponents<RequestHandler>({ expressApp: app }));
app.get('/', (req: Request, res: Response) => { app.get('/', (req: Request, res: Response) => {
res.send('Hello from the test server! Navigate to /test/tooltip to see the tooltip component test page.'); res.send('Hello from the test server! Navigate to /test/tooltip to see the tooltip component test page.');