From 9a7c780957987c06c764c94b72c97c6696a67c18 Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Sun, 20 Oct 2024 12:43:36 -0300 Subject: [PATCH] Export actor proxy Signed-off-by: Marcos Candeia --- src/actors/mod.ts | 1 + src/actors/proxy.ts | 4 ++-- src/actors/proxyutil.ts | 13 ++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/actors/mod.ts b/src/actors/mod.ts index 3742377..dfee48b 100644 --- a/src/actors/mod.ts +++ b/src/actors/mod.ts @@ -2,6 +2,7 @@ export interface Actor { } +export type { ActorProxy } from "./proxyutil.ts"; export { ActorRuntime } from "./runtime.ts"; export type { ActorConstructor } from "./runtime.ts"; export { ActorState } from "./state.ts"; diff --git a/src/actors/proxy.ts b/src/actors/proxy.ts index 4bc4bbe..fed3059 100644 --- a/src/actors/proxy.ts +++ b/src/actors/proxy.ts @@ -1,5 +1,5 @@ // deno-lint-ignore-file no-explicit-any -import { create, createHttpInvoker, type Promisify } from "./proxyutil.ts"; +import { create, createHttpInvoker, type ActorProxy } from "./proxyutil.ts"; import type { Actor, ActorConstructor } from "./runtime.ts"; export interface ActorsServer { @@ -18,7 +18,7 @@ export const actors = { proxy: ( actor: ActorConstructor | string, options?: ActorsOptions | undefined, - ): { id: (id: string) => Promisify } => { + ): { id: (id: string) => ActorProxy } => { const factory = (id: string) => createHttpInvoker(id, options); return create(actor, factory); }, diff --git a/src/actors/proxyutil.ts b/src/actors/proxyutil.ts index c4201dd..b172acd 100644 --- a/src/actors/proxyutil.ts +++ b/src/actors/proxyutil.ts @@ -138,12 +138,15 @@ export type PromisifyKey = Actor[key] extends : { (...args: Args): Promise } : Actor[key]; -export type Promisify = +/** + * Represents an actor proxy. + */ +export type ActorProxy = & { [key in keyof Actor]: PromisifyKey; } & (Actor extends { metadata?: infer TMetadata } ? { - withMetadata(metadata: TMetadata): Promisify; + withMetadata(metadata: TMetadata): ActorProxy; } // deno-lint-ignore ban-types : {}); @@ -288,11 +291,11 @@ export const create = ( actor: ActorConstructor | string, invokerFactory: (id: string) => ActorInvoker, metadata?: unknown, -): { id: (id: string) => Promisify } => { +): { id: (id: string) => ActorProxy } => { const name = typeof actor === "string" ? actor : actor.name; return { - id: (id: string): Promisify => { - return new Proxy>({} as Promisify, { + id: (id: string): ActorProxy => { + return new Proxy>({} as ActorProxy, { get: (_, method) => { if (method === "withMetadata") { return (m: unknown) => create(actor, invokerFactory, m).id(id);