Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Nov 20, 2023
1 parent 3eef402 commit ab8a950
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 33 deletions.
29 changes: 29 additions & 0 deletions src/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,32 @@ export declare const CIRCUIT_CLOSE: "close";
export declare const CIRCUIT_HALF_OPEN: "half_open";
export declare const CIRCUIT_HALF_OPEN_WAIT: "half_open_wait";
export declare const CIRCUIT_OPEN: "open";

export declare const FAILED_PROCESSING_PACKET: "failedProcessingPacket";
export declare const FAILED_SEND_REQUEST_PACKET: "failedSendRequestPacket";
export declare const FAILED_SEND_EVENT_PACKET: "failedSendEventPacket";
export declare const FAILED_SEND_RESPONSE_PACKET: "failedSendResponsePacket";
export declare const FAILED_NODES_DISCOVERY: "failedNodesDiscovery";
export declare const FAILED_NODE_DISCOVERY: "failedNodeDiscovery";
export declare const FAILED_SEND_INFO_PACKET: "failedSendInfoPacket";
export declare const FAILED_SEND_PING_PACKET: "failedSendPingPacket";
export declare const FAILED_SEND_PONG_PACKET: "failedSendPongPacket";
export declare const FAILED_SEND_HEARTBEAT_PACKET: "failedSendHeartbeatPacket";
export declare const FAILED_STOPPING_SERVICES: "failedServicesStop";
export declare const FAILED_LOAD_SERVICE: "failedServiceLoad";
export declare const FAILED_RESTART_SERVICE: "failedServiceRestart";
export declare const FAILED_DESTRUCTION_SERVICE: "failedServiceDestruction";
export declare const CLIENT_ERROR: "clientError";
export declare const FAILED_SEND_PING: "failedSendPing";
export declare const FAILED_COLLECT_KEYS: "failedCollectKeys";
export declare const FAILED_SEND_INFO: "failedSendInfo";
export declare const FAILED_KEY_SCAN: "failedKeyScan";
export declare const FAILED_PUBLISHER_ERROR: "publisherError";
export declare const FAILED_CONSUMER_ERROR: "consumerError";
export declare const FAILED_TOPIC_CREATION: "failedTopicCreation";
export declare const FAILED_CONNECTION_ERROR: "failedConnection";
export declare const FAILED_CHANNEL_ERROR: "failedChannel";
export declare const FAILED_REQUEST_ACK: "requestAck";
export declare const FAILED_DISCONNECTION: "failedDisconnection";
export declare const FAILED_PUBLISH_BALANCED_EVENT: "failedPublishBalancedEvent";
export declare const FAILED_PUBLISH_BALANCED_REQUEST: "publishBalancedRequest";
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
/*
* moleculer
* Copyright (c) 2018 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

Expand Down
2 changes: 1 addition & 1 deletion src/context.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ declare class Context<TParams = unknown, TMeta extends object = {}, TLocals = Re

cachedResult: boolean;

constructor(broker: ServiceBroker, endpoint: ActionEndpoint|EventEndpoint);
constructor(broker: ServiceBroker, endpoint?: ActionEndpoint|EventEndpoint);

setEndpoint(endpoint: ActionEndpoint|EventEndpoint): void;

Expand Down
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function mergeMeta(ctx, newMeta) {
/**
* Context class for action calls
*
* @class Context
* @type import("./context").Context
*/
class Context {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export declare class Regenerator {

restore(plainError: PlainMoleculerError, payload: Record<string, any>): Error;

extractPlainError(err: Error): PlainMoleculerError;
extractPlainError(err: Error, payload?: Record<string, any>): PlainMoleculerError;

restoreCustomError(
plainError: PlainMoleculerError,
Expand Down
4 changes: 2 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* moleculer
* Copyright (c) 2018 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

Expand Down Expand Up @@ -83,7 +83,7 @@ class MoleculerRetryableError extends MoleculerError {
* @param {String?} message
* @param {Number?} code
* @param {String?} type
* @param {any} data
* @param {any?} data
*
* @memberof MoleculerRetryableError
*/
Expand Down
7 changes: 6 additions & 1 deletion src/internals.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
/*
* moleculer
* Copyright (c) 2020 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

Expand All @@ -9,7 +10,11 @@
const { MoleculerClientError } = require("./errors");
const utils = require("./utils");

/**
* Internal service ($node.*)
*/
module.exports = function () {
/** @type import("./service").ServiceSchema */
const schema = {
name: "$node",

Expand Down
162 changes: 162 additions & 0 deletions src/metrics/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,165 @@ export declare const TYPE_COUNTER = "counter";
export declare const TYPE_GAUGE = "gauge";
export declare const TYPE_HISTOGRAM = "histogram";
export declare const TYPE_INFO = "info";


export declare const PROCESS_ARGUMENTS: "process.arguments";

export declare const PROCESS_PID = "process.pid";
export declare const PROCESS_PPID = "process.ppid";

export declare const PROCESS_MEMORY_HEAP_SIZE_TOTAL = "process.memory.heap.size.total";
export declare const PROCESS_MEMORY_HEAP_SIZE_USED = "process.memory.heap.size.used";
export declare const PROCESS_MEMORY_RSS = "process.memory.rss";
export declare const PROCESS_MEMORY_EXTERNAL = "process.memory.external";

export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_TOTAL = "process.memory.heap.space.size.total";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_USED = "process.memory.heap.space.size.used";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_AVAILABLE = "process.memory.heap.space.size.available";
export declare const PROCESS_MEMORY_HEAP_SPACE_SIZE_PHYSICAL = "process.memory.heap.space.size.physical";

export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_TOTAL = "process.memory.heap.stat.heap.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_EXECUTABLE_SIZE_TOTAL = "process.memory.heap.stat.executable.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_PHYSICAL_SIZE_TOTAL = "process.memory.heap.stat.physical.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_AVAILABLE_SIZE_TOTAL = "process.memory.heap.stat.available.size.total";
export declare const PROCESS_MEMORY_HEAP_STAT_USED_HEAP_SIZE = "process.memory.heap.stat.used.heap.size";
export declare const PROCESS_MEMORY_HEAP_STAT_HEAP_SIZE_LIMIT = "process.memory.heap.stat.heap.size.limit";
export declare const PROCESS_MEMORY_HEAP_STAT_MALLOCATED_MEMORY = "process.memory.heap.stat.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_STAT_PEAK_MALLOCATED_MEMORY = "process.memory.heap.stat.peak.mallocated.memory";
export declare const PROCESS_MEMORY_HEAP_STAT_ZAP_GARBAGE = "process.memory.heap.stat.zap.garbage";

export declare const PROCESS_UPTIME = "process.uptime";
export declare const PROCESS_INTERNAL_ACTIVE_HANDLES = "process.internal.active.handles";
export declare const PROCESS_INTERNAL_ACTIVE_REQUESTS = "process.internal.active.requests";

export declare const PROCESS_VERSIONS_NODE = "process.versions.node";

export declare const OS_MEMORY_FREE: "os.memory.free";
export declare const OS_MEMORY_USED: "os.memory.used";
export declare const OS_MEMORY_TOTAL: "os.memory.total";
export declare const OS_UPTIME: "os.uptime";
export declare const OS_TYPE: "os.type";
export declare const OS_RELEASE: "os.release";
export declare const OS_HOSTNAME: "os.hostname";
export declare const OS_ARCH: "os.arch";
export declare const OS_PLATFORM: "os.platform";
export declare const OS_USER_UID: "os.user.uid";
export declare const OS_USER_GID: "os.user.gid";
export declare const OS_USER_USERNAME: "os.user.username";
export declare const OS_USER_HOMEDIR: "os.user.homedir";

export declare const OS_DATETIME_UNIX: "os.datetime.unix";
export declare const OS_DATETIME_ISO: "os.datetime.iso";
export declare const OS_DATETIME_UTC: "os.datetime.utc";
export declare const OS_DATETIME_TZ_OFFSET: "os.datetime.tz.offset";

export declare const OS_NETWORK_ADDRESS: "os.network.address";
export declare const OS_NETWORK_MAC: "os.network.mac";
export declare const OS_CPU_LOAD_1: "os.cpu.load.1";
export declare const OS_CPU_LOAD_5: "os.cpu.load.5";
export declare const OS_CPU_LOAD_15: "os.cpu.load.15";
export declare const OS_CPU_UTILIZATION: "os.cpu.utilization";
export declare const OS_CPU_USER: "os.cpu.user";
export declare const OS_CPU_SYSTEM: "os.cpu.system";
export declare const OS_CPU_TOTAL: "os.cpu.total";
export declare const OS_CPU_INFO_MODEL: "os.cpu.info.model";
export declare const OS_CPU_INFO_SPEED: "os.cpu.info.speed";
export declare const OS_CPU_INFO_TIMES_USER: "os.cpu.info.times.user";
export declare const OS_CPU_INFO_TIMES_SYS: "os.cpu.info.times.sys";

export declare const MOLECULER_NODE_TYPE: "moleculer.node.type";
export declare const MOLECULER_NODE_VERSIONS_MOLECULER: "moleculer.node.versions.moleculer";
export declare const MOLECULER_NODE_VERSIONS_LANG: "moleculer.node.versions.lang";
export declare const MOLECULER_NODE_VERSIONS_PROTOCOL: "moleculer.node.versions.protocol";
export declare const MOLECULER_BROKER_NAMESPACE: "moleculer.broker.namespace";
export declare const MOLECULER_BROKER_STARTED: "moleculer.broker.started";
export declare const MOLECULER_BROKER_LOCAL_SERVICES_TOTAL: "moleculer.broker.local.services.total";
export declare const MOLECULER_BROKER_MIDDLEWARES_TOTAL: "moleculer.broker.middlewares.total";
export declare const MOLECULER_REGISTRY_NODES_TOTAL: "moleculer.registry.nodes.total";
export declare const MOLECULER_REGISTRY_NODES_ONLINE_TOTAL: "moleculer.registry.nodes.online.total";
export declare const MOLECULER_REGISTRY_SERVICES_TOTAL: "moleculer.registry.services.total";
export declare const MOLECULER_REGISTRY_SERVICE_ENDPOINTS_TOTAL: "moleculer.registry.service.endpoints.total";
export declare const MOLECULER_REGISTRY_ACTIONS_TOTAL: "moleculer.registry.actions.total";
export declare const MOLECULER_REGISTRY_ACTION_ENDPOINTS_TOTAL: "moleculer.registry.action.endpoints.total";
export declare const MOLECULER_REGISTRY_EVENTS_TOTAL: "moleculer.registry.events.total";
export declare const MOLECULER_REGISTRY_EVENT_ENDPOINTS_TOTAL: "moleculer.registry.event.endpoints.total";
export declare const MOLECULER_REQUEST_TOTAL: "moleculer.request.total";
export declare const MOLECULER_REQUEST_ACTIVE: "moleculer.request.active";
export declare const MOLECULER_REQUEST_ERROR_TOTAL: "moleculer.request.error.total";
export declare const MOLECULER_REQUEST_TIME: "moleculer.request.time";
export declare const MOLECULER_REQUEST_LEVELS: "moleculer.request.levels";
export declare const MOLECULER_EVENT_EMIT_TOTAL: "moleculer.event.emit.total";
export declare const MOLECULER_EVENT_BROADCAST_TOTAL: "moleculer.event.broadcast.total";
export declare const MOLECULER_EVENT_BROADCASTLOCAL_TOTAL: "moleculer.event.broadcast-local.total";
export declare const MOLECULER_EVENT_RECEIVED_TOTAL: "moleculer.event.received.total";
export declare const MOLECULER_EVENT_RECEIVED_ACTIVE: "moleculer.event.received.active";
export declare const MOLECULER_EVENT_RECEIVED_ERROR_TOTAL: "moleculer.event.received.error.total";
export declare const MOLECULER_EVENT_RECEIVED_TIME: "moleculer.event.received.time";
export declare const MOLECULER_TRANSIT_PUBLISH_TOTAL: "moleculer.transit.publish.total";
export declare const MOLECULER_TRANSIT_RECEIVE_TOTAL: "moleculer.transit.receive.total";
export declare const MOLECULER_TRANSIT_REQUESTS_ACTIVE: "moleculer.transit.requests.active";
export declare const MOLECULER_TRANSIT_STREAMS_SEND_ACTIVE: "moleculer.transit.streams.send.active";
export declare const MOLECULER_TRANSIT_READY: "moleculer.transit.ready";
export declare const MOLECULER_TRANSIT_CONNECTED: "moleculer.transit.connected";
export declare const MOLECULER_TRANSIT_PONG_TIME: "moleculer.transit.pong.time";
export declare const MOLECULER_TRANSIT_PONG_SYSTIME_DIFF: "moleculer.transit.pong.systime-diff";
export declare const MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL: "moleculer.transit.orphan.response.total";
export declare const MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL: "moleculer.transporter.packets.sent.total";
export declare const MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES: "moleculer.transporter.packets.sent.bytes";
export declare const MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL: "moleculer.transporter.packets.received.total";
export declare const MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES: "moleculer.transporter.packets.received.bytes";
export declare const MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE: "moleculer.circuit-breaker.opened.active";
export declare const MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL: "moleculer.circuit-breaker.opened.total";
export declare const MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE: "moleculer.circuit-breaker.half-opened.active";
export declare const MOLECULER_REQUEST_FALLBACK_TOTAL: "moleculer.request.fallback.total";
export declare const MOLECULER_REQUEST_BULKHEAD_INFLIGHT: "moleculer.request.bulkhead.inflight";
export declare const MOLECULER_REQUEST_BULKHEAD_QUEUE_SIZE: "moleculer.request.bulkhead.queue.size";
export declare const MOLECULER_EVENT_BULKHEAD_INFLIGHT: "moleculer.event.bulkhead.inflight";
export declare const MOLECULER_EVENT_BULKHEAD_QUEUE_SIZE: "moleculer.event.bulkhead.queue.size";
export declare const MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL: "moleculer.request.retry.attempts.total";
export declare const MOLECULER_REQUEST_TIMEOUT_TOTAL: "moleculer.request.timeout.total";
export declare const MOLECULER_CACHER_GET_TOTAL: "moleculer.cacher.get.total";
export declare const MOLECULER_CACHER_GET_TIME: "moleculer.cacher.get.time";
export declare const MOLECULER_CACHER_FOUND_TOTAL: "moleculer.cacher.found.total";
export declare const MOLECULER_CACHER_SET_TOTAL: "moleculer.cacher.set.total";
export declare const MOLECULER_CACHER_SET_TIME: "moleculer.cacher.set.time";
export declare const MOLECULER_CACHER_DEL_TOTAL: "moleculer.cacher.del.total";
export declare const MOLECULER_CACHER_DEL_TIME: "moleculer.cacher.del.time";
export declare const MOLECULER_CACHER_CLEAN_TOTAL: "moleculer.cacher.clean.total";
export declare const MOLECULER_CACHER_CLEAN_TIME: "moleculer.cacher.clean.time";
export declare const MOLECULER_CACHER_EXPIRED_TOTAL: "moleculer.cacher.expired.total";
export declare const MOLECULER_DISCOVERER_REDIS_COLLECT_TOTAL: "moleculer.discoverer.redis.collect.total";
export declare const MOLECULER_DISCOVERER_REDIS_COLLECT_TIME: "moleculer.discoverer.redis.collect.time";
export declare const MOLECULER_DISCOVERER_ETCD_COLLECT_TOTAL: "moleculer.discoverer.etcd.collect.total";
export declare const MOLECULER_DISCOVERER_ETCD_COLLECT_TIME: "moleculer.discoverer.etcd.collect.time";

export declare const UNIT_BIT: "bit";
export declare const UNIT_BYTE: "byte";
export declare const UNIT_KILOBYTES: "kilobyte";
export declare const UNIT_MEGABYTE: "megabyte";
export declare const UNIT_GIGABYTE: "gigabyte";
export declare const UNIT_TERRABYTE: "terrabyte";
export declare const UNIT_PETABYTE: "petabyte";
export declare const UNIT_EXOBYTE: "exabyte";

export declare const UNIT_NANOSECONDS: "nanosecond";
export declare const UNIT_MICROSECONDS: "microsecond";
export declare const UNIT_MILLISECONDS: "millisecond";
export declare const UNIT_SECONDS: "second";
export declare const UNIT_MINUTE: "minute";
export declare const UNIT_HOUR: "hour";
export declare const UNIT_DAY: "day";
export declare const UNIT_WEEK: "week";
export declare const UNIT_MONTH: "month";
export declare const UNIT_YEAR: "year";

export declare const UNIT_HANDLE: "handle";
export declare const UNIT_CPU: "cpu";
export declare const UNIT_GHZ: "GHz";

export declare const UNIT_REQUEST: "request";
export declare const UNIT_CONNECTION: "connection";
export declare const UNIT_PACKET: "packet";
export declare const UNIT_MESSAGE: "message";
export declare const UNIT_STREAM: "stream";
export declare const UNIT_EVENT: "event";
2 changes: 1 addition & 1 deletion src/packets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ export declare class Packet {

payload: PacketPayload;

constructor(type: string, target: string, payload?: any);
constructor(type: string, target?: string|null, payload?: any);
}
11 changes: 10 additions & 1 deletion src/registry/registry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import BaseStrategy = require("../strategies/base");
import type { ActionCatalogListOptions } from "./action-catalog";
import type { Logger } from "../logger-factory";
import type { BrokerRegistryOptions } from "../service-broker";
import ServiceCatalog = require("./service-catalog");
import ActionCatalog = require("./action-catalog");
import NodeCatalog = require("./node-catalog");
import EventCatalog = require("./event-catalog");

declare namespace ServiceRegistry {}

Expand All @@ -22,6 +25,12 @@ declare class ServiceRegistry {
actions: ActionCatalog;
events: any;

getServiceList(opts?: ActionCatalogListOptions): ReturnType<ActionCatalog["list"]>;
getServiceList(opts?: ActionCatalogListOptions): Promise<ReturnType<ServiceCatalog["list"]>>;

getNodeList(opts?: ActionCatalogListOptions): Promise<ReturnType<NodeCatalog["list"]>>;

getActionList(opts?: ActionCatalogListOptions): Promise<ReturnType<ActionCatalog["list"]>>;

getEventList(opts?: ActionCatalogListOptions): Promise<ReturnType<EventCatalog["list"]>>;
}
export = ServiceRegistry;
8 changes: 5 additions & 3 deletions src/service-broker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type BrokerNode = require("./registry/node");
import type ActionEndpoint = require("./registry/endpoint-action");
import type EventEndpoint = require("./registry/endpoint-event");
import type Service = require("./service");
import type { Stream } from "stream";

declare namespace ServiceBroker {
type BrokerSyncLifecycleHandler = (broker: ServiceBroker) => void;
Expand Down Expand Up @@ -92,7 +93,7 @@ declare namespace ServiceBroker {

ServiceFactory?: typeof Service;
ContextFactory?: typeof Context;
Promise?: PromiseConstructorLike;
Promise?: PromiseConstructor;

created?: BrokerSyncLifecycleHandler;
started?: BrokerAsyncLifecycleHandler;
Expand Down Expand Up @@ -229,6 +230,7 @@ declare namespace ServiceBroker {
paramsCloning?: boolean;
caller?: string;
headers?: Record<string, any>;
stream?: Stream;
}

export interface MCallCallingOptions extends CallingOptions {
Expand All @@ -255,15 +257,15 @@ declare class ServiceBroker {

static defaultOptions: ServiceBroker.ServiceBrokerOptions;

static Promise: PromiseConstructorLike;
static Promise: PromiseConstructor;

MOLECULER_VERSION: string;

PROTOCOL_VERSION: "5";

options: ServiceBroker.ServiceBrokerOptions;

Promise: PromiseConstructorLike;
Promise: PromiseConstructor;

ServiceFactory: typeof Service;

Expand Down
2 changes: 1 addition & 1 deletion src/service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ declare class Service<S = Service.ServiceSettingSchema> implements Service.Servi
broker: ServiceBroker;
logger: Logger;
actions: Service.ServiceActions;
Promise: PromiseConstructorLike;
Promise: PromiseConstructor;

_init(): void;
_start(): Promise<void>;
Expand Down
Loading

0 comments on commit ab8a950

Please sign in to comment.