@akala/core
Version:
34 lines • 1.31 kB
JavaScript
import ErrorWithStatus, { HttpStatusCode } from "../errorWithStatus.js";
import { UrlHandler } from "../url-handler.js";
import { EventBus2AsyncEventBus } from "./event-bus.js";
import { EventEmitter } from "./event-emitter.js";
export * from "./async.js";
export * from './event-bus.js';
export * from './shared.js';
export * from './event-emitter.js';
export const eventBuses = new UrlHandler(true);
export const asyncEventBuses = new UrlHandler(true);
eventBuses.useProtocol('memory', (_, config) => {
return Promise.resolve(new EventEmitter(null, config?.abort));
});
asyncEventBuses.protocol.useMiddleware({
async handle(url, config) {
try {
const error = await handle.call(eventBuses, url, config);
if (error instanceof ErrorWithStatus && error?.statusCode == HttpStatusCode.NotFound)
return undefined;
return error;
}
catch (eventBus) {
if (eventBus)
throw new EventBus2AsyncEventBus(eventBus);
}
}
});
const handle = eventBuses.handle;
eventBuses.handle = async function (url, config) {
const result = await handle.call(this, url, config);
if (result === undefined)
return new Error(`Unsupported URL mechanism (${url})`);
};
//# sourceMappingURL=index.js.map