Skip to content

Commit

Permalink
Merge pull request #1225 from shawnmcknight/improve-registry-types
Browse files Browse the repository at this point in the history
Update some registry types around ActionCatalog
  • Loading branch information
icebob authored Jul 11, 2023
2 parents 275eda5 + b15d5aa commit e88c8e1
Showing 1 changed file with 58 additions and 29 deletions.
87 changes: 58 additions & 29 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,26 +1129,6 @@ declare namespace Moleculer {
options?: CallingOptions;
}

interface Endpoint {
broker: ServiceBroker;

id: string;
node: GenericObject;

local: boolean;
state: boolean;
}

interface ActionEndpoint extends Endpoint {
service: Service;
action: ActionSchema;
}

interface EventEndpoint extends Endpoint {
service: Service;
event: EventSchema;
}

interface PongResponse {
nodeID: string;
elapsedTime: number;
Expand Down Expand Up @@ -1718,13 +1698,6 @@ declare namespace Moleculer {
publish(packet: Packet): Promise<void>;
}

interface ActionCatalogListOptions {
onlyLocal?: boolean;
onlyAvailable?: boolean;
skipInternal?: boolean;
withEndpoints?: boolean;
}

interface ServiceListCatalogOptions {
onlyLocal?: boolean;
onlyAvailable?: boolean;
Expand All @@ -1745,15 +1718,71 @@ declare namespace Moleculer {

nodes: any;
services: any;
actions: any;
actions: ActionCatalog;
events: any;

getServiceList<S = ServiceSettingSchema>(
opts?: ServiceListCatalogOptions
): ServiceSchema<S>[];
getActionList(opts?: ActionCatalogListOptions): ActionSchema[];
getActionList(opts?: ActionCatalogListOptions): ReturnType<ActionCatalog["list"]>;
}

abstract class Endpoint {
broker: ServiceBroker;

id: string;
node: GenericObject;

local: boolean;
state: boolean;
}

class ActionEndpoint extends Endpoint {
service: Service;
action: ActionSchema;
}

class EventEndpoint extends Endpoint {
service: Service;
event: EventSchema;
}

class EndpointList {
endpoints: (ActionEndpoint | EventEndpoint)[];
}

interface ActionCatalogListOptions {
onlyLocal?: boolean;
onlyAvailable?: boolean;
skipInternal?: boolean;
withEndpoints?: boolean;
}

interface ActionCatalogListResult {
name: string;
count: number;
hasLocal: boolean;
available: boolean;
action?: Omit<ActionSchema, "handler" | "remoteHandler" | "service">;
endpoints?: Pick<Endpoint, "id" | "state">[];
}

class ActionCatalog {
add(node: BrokerNode, service: ServiceItem, action: ActionSchema): EndpointList;

get(actionName: string): EndpointList | undefined;

isAvailable(actionName: string): boolean;

removeByService(service: ServiceItem): void;

remove(actionName: string, nodeID: string): void;

list(opts: ActionCatalogListOptions): ActionCatalogListResult[];
}

class ServiceItem {}

class AsyncStorage {
broker: ServiceBroker;
store: Map<string, any>;
Expand Down

0 comments on commit e88c8e1

Please sign in to comment.