diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index e1ecf5d..bb01c6d 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -170,30 +170,40 @@ export namespace make { i: (_: H, props: NoInfer

) => Effect.Effect, ): Component } +} - export interface Options { - readonly untraced?: boolean - readonly finalizerExecutionMode?: "sync" | "fork" - readonly finalizerExecutionStrategy?: ExecutionStrategy.ExecutionStrategy +export const make: ( + & make.Gen + & (( + spanName: string, + spanOptions?: Tracer.SpanOptions, + ) => make.Gen) +) = (spanNameOrBody: Function | string, ...pipeables: any[]) => { + if (typeof spanNameOrBody !== "string") { + const displayName = displayNameFromBody(spanNameOrBody) + return Object.setPrototypeOf({ + body: displayName + ? Effect.fn(displayName)(spanNameOrBody as any, ...pipeables as []) + : Effect.fn(spanNameOrBody as any, ...pipeables), + displayName, + }, ComponentProto) + } + else { + const spanOptions = pipeables[0] + return (body: any, ...pipeables: any[]) => Object.setPrototypeOf({ + body: Effect.fn(spanNameOrBody, spanOptions)(body, ...pipeables as []), + displayName: displayNameFromBody(body) ?? spanNameOrBody, + }, ComponentProto) } } -export const make: make.Gen = (...pipeables: readonly [any]) => { - const displayName: string = !String.isEmpty(pipeables[0].name) ? pipeables[0].name : undefined - - return Object.setPrototypeOf({ - body: displayName - ? Effect.fn(displayName)(...pipeables) - : Effect.fn(...pipeables), - displayName, - }, ComponentProto) -} - -export const makeUntraced: make.Gen = (...pipeables: readonly [any]) => Object.setPrototypeOf({ - body: Effect.fnUntraced(...pipeables), - displayName: !String.isEmpty(pipeables[0].name) ? pipeables[0].name : undefined, +export const makeUntraced: make.Gen = (body: Function, ...pipeables: any[]) => Object.setPrototypeOf({ + body: Effect.fnUntraced(body as any, ...pipeables as []), + displayName: displayNameFromBody(body), }, ComponentProto) +const displayNameFromBody = (body: Function) => !String.isEmpty(body.name) ? body.name : undefined + export const withRuntime: { (