Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Nov 22, 2023
1 parent ab8a950 commit 59fbdc5
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/registry/endpoint-list.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import BaseStrategy = require("../strategies/base");
import Endpoint = require("./endpoint");
import ActionEndpoint = require("./endpoint-action");
import EventEndpoint = require("./endpoint-event");
import { Registry, ServiceBroker } from "./event-catalog";

declare class EndpointList {
constructor(registry: Registry, broker: ServiceBroker, name: string, group: string, EndPointFactory?: typeof Endpoint, StrategyFactory?: BaseStrategy, strategyOptions?: Record<string, any>);

endpoints: (ActionEndpoint | EventEndpoint)[];
}
export = EndpointList;
26 changes: 19 additions & 7 deletions src/registry/event-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const Strategies = require("../strategies");
const EndpointList = require("./endpoint-list");
const EventEndpoint = require("./endpoint-event");

/**
* Import types
*
* @typedef {import("./registry")} Registry
* @typedef {import("../service")} ServiceItem
* @typedef {import("../service-broker")} ServiceBroker
* @typedef {import("../context")} Context
* @typedef {import("./node")} Node
*/

/**
* Catalog for events
*
Expand Down Expand Up @@ -153,11 +163,7 @@ class EventCatalog {
/**
* Call local service handlers
*
* @param {String} eventName
* @param {any} payload
* @param {Array<String>?} groupNames
* @param {String} nodeID
* @param {boolean} broadcast
* @param {Context} ctx
* @returns {Promise<any>}
*
* @memberof EventCatalog
Expand Down Expand Up @@ -196,6 +202,7 @@ class EventCatalog {

return this.broker.Promise.allSettled(promises).then(results => {
const err = results.find(r => r.status == "rejected");
// @ts-ignore
if (err) return this.broker.Promise.reject(err.reason);
return true;
});
Expand All @@ -204,7 +211,7 @@ class EventCatalog {
/**
* Call local event handler and handles unhandled promise rejections.
*
* @param {Context} ctx
* @param {any} ctx
*
* @memberof EventCatalog
*/
Expand Down Expand Up @@ -240,7 +247,12 @@ class EventCatalog {
/**
* Get a filtered list of events
*
* @param {Object} {onlyLocal = false, onlyAvailable = false, skipInternal = false, withEndpoints = false}
* @param {Object} opts
* @param {Boolean} [opts.onlyLocal = false]
* @param {Boolean} [opts.onlyAvailable = false]
* @param {Boolean} [opts.skipInternal = false]
* @param {Boolean} [opts.withEndpoints = false]
*
* @returns {Array}
*
* @memberof EventCatalog
Expand Down
13 changes: 11 additions & 2 deletions src/registry/node-catalog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* moleculer
* Copyright (c) 2020 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

Expand All @@ -11,6 +11,13 @@ const os = require("os");
const Node = require("./node");
const { getIpList } = require("../utils");

/**
* Import types
*
* @typedef {import("./registry")} Registry
* @typedef {import("../service-broker")} ServiceBroker
*/

/**
* Catalog for nodes
*
Expand Down Expand Up @@ -202,7 +209,9 @@ class NodeCatalog {
/**
* Get a node list
*
* @param {Object} {onlyAvailable = false, withServices = false}
* @param {Object} opts
* @param {Boolean} [opts.onlyAvailable = false]
* @param {Boolean} [opts.withServices = false]
* @returns
* @memberof NodeCatalog
*/
Expand Down
2 changes: 2 additions & 0 deletions src/registry/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare class BrokerNode {
seq: number;
offlineSince: number | null;

constructor(id: string);

heartbeat(payload: Record<string, any>): void;
disconnected(): void;
}
Expand Down
6 changes: 6 additions & 0 deletions src/registry/registry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ServiceCatalog = require("./service-catalog");
import ActionCatalog = require("./action-catalog");
import NodeCatalog = require("./node-catalog");
import EventCatalog = require("./event-catalog");
import Node = require("./node");

declare namespace ServiceRegistry {}

Expand All @@ -32,5 +33,10 @@ declare class ServiceRegistry {
getActionList(opts?: ActionCatalogListOptions): Promise<ReturnType<ActionCatalog["list"]>>;

getEventList(opts?: ActionCatalogListOptions): Promise<ReturnType<EventCatalog["list"]>>;

updateMetrics(): void;

registerServices(node: Node, serviceList: Record<string, any>[]): void;
unregisterServicesByNode(nodeID: string): void;
}
export = ServiceRegistry;
16 changes: 15 additions & 1 deletion src/registry/service-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const _ = require("lodash");
const ServiceItem = require("./service-item");
const { removeFromArray } = require("../utils");

/**
* Import types
*
* @typedef {import("./registry")} Registry
* @typedef {import("./node")} Node
* @typedef {import("../service-broker")} ServiceBroker
*/

/**
* Catalog for services
*
Expand Down Expand Up @@ -75,7 +83,13 @@ class ServiceCatalog {
/**
* Get a filtered list of services with actions
*
* @param {Object} {onlyLocal = false, onlyAvailable = false, skipInternal = false, withActions = false, withEvents = false, grouping = false}
* @param {Object} opts
* @param {Boolean} [opts.onlyLocal = false]
* @param {Boolean} [opts.onlyAvailable = false]
* @param {Boolean} [opts.skipInternal = false]
* @param {Boolean} [opts.withActions = false]
* @param {Boolean} [opts.withEvents = false]
* @param {Boolean} [opts.grouping = false]
* @returns {Array}
*
* @memberof Registry
Expand Down
6 changes: 5 additions & 1 deletion src/registry/service-item.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
declare class ServiceItem {}
import Node = require("./node");

declare class ServiceItem {
constructor(node: Node, service: Record<string, any>, local: boolean);
}
export = ServiceItem;
1 change: 1 addition & 0 deletions src/runner.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ServiceBroker = require("./service-broker");
import Service = require("./service");
import type { ServiceBrokerOptions} from "./service-broker";
import { Worker } from "cluster";

declare namespace Runner {
/**
Expand Down
5 changes: 4 additions & 1 deletion src/strategies/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export {
RandomStrategy as Random,
CpuUsageStrategy as CpuUsage,
LatencyStrategy as Latency,
ShardStrategy as Shard
ShardStrategy as Shard,
};

export declare function resolve(opts: Record<string, any>|string): BaseStrategy;
export declare function register(name: string, value: BaseStrategy): void;

0 comments on commit 59fbdc5

Please sign in to comment.