Skip to content

Commit

Permalink
fix: add container as an option in url handler
Browse files Browse the repository at this point in the history
  • Loading branch information
npenin committed Nov 22, 2024
1 parent d0a1c08 commit 712e112
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/commands/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export class Cli

export async function connect(socketPath: string | URL, signal: AbortSignal, resolvedMetadata?: Metadata.Container): Promise<Container<unknown>>
{
const { processor, getMetadata } = await handlers.process(new URL(socketPath), { signal }, {})
const container = new Container('proxy', null);
const { processor, getMetadata } = await handlers.process(new URL(socketPath), { signal, container }, {})

const meta = resolvedMetadata || await getMetadata();
const container = new Container(meta.name, null, processor);
container.name = meta.name;
container.processor.useMiddleware(20, processor);

registerCommands(meta.commands, null, container);
return container;
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/src/protocol-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Container } from "./model/container.js";
export type HandlerResult<T> = { processor: T, getMetadata(): Promise<Metadata.Container> };
export type handler<T> = (arg1: URL, arg2: HandlerResult<T>) => Promise<void>

export const handlers = new UrlHandler<[URL, { signal: AbortSignal }, Partial<HandlerResult<ICommandProcessor>>], HandlerResult<ICommandProcessor>>();
export const handlers = new UrlHandler<[URL, { signal: AbortSignal, container?: Container<unknown> }, Partial<HandlerResult<ICommandProcessor>>], HandlerResult<ICommandProcessor>>();

export type ServerHandler<T = { signal: AbortSignal }> = (container: Container<unknown>, options: T) => Promise<void>

Expand Down
2 changes: 1 addition & 1 deletion packages/commands/src/serve-metadata.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function connectByPreference<T = unknown>(options: ServeMetadata, s

export async function connectWith<T>(connectionString: string, options: object, signal: AbortSignal, container?: Container<T>): Promise<ICommandProcessor>
{
const { processor, getMetadata } = await handlers.process(new URL(connectionString), { signal, ...options }, {})
const { processor, getMetadata } = await handlers.process(new URL(connectionString), { signal, ...options, container }, {})

if (container)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/src/serve-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function connectByPreference<T = unknown>(options: ServeMetadata, s

export async function connectWith<T>(connectionString: string, options: object, signal: AbortSignal, container?: Container<T>): Promise<ICommandProcessor>
{
const { processor, getMetadata } = await handlers.process(new URL(connectionString), { signal, ...options }, {})
const { processor, getMetadata } = await handlers.process(new URL(connectionString), { signal, ...options, container }, {})

if (container)
{
Expand Down

0 comments on commit 712e112

Please sign in to comment.