From e4b36af730741cf788d95001223f758a29f03921 Mon Sep 17 00:00:00 2001 From: Icebob Date: Sun, 10 Dec 2023 16:17:48 +0100 Subject: [PATCH] organize index.d.ts --- index.d.ts | 99 +++++++++++++++++++++--------- src/runner.d.ts | 6 +- src/service-broker.d.ts | 8 +-- src/service-broker.js | 6 +- src/service.d.ts | 4 +- src/tracing/exporters/console.d.ts | 2 +- 6 files changed, 83 insertions(+), 42 deletions(-) diff --git a/index.d.ts b/index.d.ts index 10a7e25fc..c55722853 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,10 @@ +// --- SERVICE BROKER --- + import ServiceBroker = require("./src/service-broker"); export { ServiceBroker }; -export type { ServiceBrokerOptions, CallingOptions } from "./src/service-broker"; +export type { BrokerOptions, CallingOptions } from "./src/service-broker"; + +// --- SERVICE --- import Service = require("./src/service"); export { Service }; @@ -17,64 +21,101 @@ export type { ServiceActions } from "./src/service"; +// --- CONTEXT --- + import Context = require("./src/context"); export { Context }; -export * as Loggers from "./src/loggers"; -export type { LogLevels } from "./src/loggers"; -export type { Logger, LoggerConfig } from "./src/logger-factory"; +// --- TRANSIT --- -export * as Cachers from "./src/cachers"; +import Transit = require("./src/transit"); +export { Transit }; +export * as Packet from "./src/packets"; -export * as Transporters from "./src/transporters"; +// --- RUNNER --- -export * as Serializers from "./src/serializers"; +import Runner = require("./src/runner"); +export { Runner }; +export type { RunnerFlags } from "./src/runner"; -export * as Strategies from "./src/strategies"; +// --- ERRORS --- -export * as Validators from "./src/validators"; -export type { ValidatorNames } from "./src/validators"; +export * as Errors from "./src/errors"; -export type { Span, TracerOptions } from "./src/tracing"; -export * as TracerExporters from "./src/tracing/exporters"; +// --- UTILS --- -export * as MetricTypes from "./src/metrics/types"; +export * as Utils from "./src/utils"; -export * as MetricReporters from "./src/metrics/reporters"; +// --- CONSTANTS --- + +export type { + CIRCUIT_CLOSE, + CIRCUIT_HALF_OPEN, + CIRCUIT_HALF_OPEN_WAIT, + CIRCUIT_OPEN +} from "./src/constants"; + +export declare const MOLECULER_VERSION: string; +export declare const PROTOCOL_VERSION: string; +export declare const INTERNAL_MIDDLEWARES: string[]; + +// --- CACHERS --- + +export * as Cachers from "./src/cachers"; + +// --- LOGGERS --- +export * as Loggers from "./src/loggers"; +export type { LogLevels } from "./src/loggers"; +export type { Logger, LoggerConfig } from "./src/logger-factory"; + +// --- METRICS --- + +export * as MetricTypes from "./src/metrics/types"; +export * as MetricReporters from "./src/metrics/reporters"; +import MetricRegistry = require("./src/metrics/registry"); +export { MetricRegistry }; export * as METRIC from "./src/metrics/constants"; -import Transit = require("./src/transit"); -export { Transit }; +// --- MIDDLEWARES --- + +export type { CallMiddlewareHandler, Middleware } from "./src/middleware"; + +// --- SERVICE REGISTRY --- import Registry = require("./src/registry"); export { Registry }; +import type EndpointList = require("./src/registry/endpoint-list"); +export type { EndpointList }; import type Endpoint = require("./src/registry/endpoint"); export type { Endpoint }; import type ActionEndpoint = require("./src/registry/endpoint-action"); export type { ActionEndpoint }; import type EventEndpoint = require("./src/registry/endpoint-event"); +import { Packet } from "./src/packets"; export type { EventEndpoint }; export * as Discoverers from "./src/registry/discoverers"; -export * as Errors from "./src/errors"; +// --- SERIALIZERS --- -export * as Utils from "./src/utils"; +export * as Serializers from "./src/serializers"; -export type { - CIRCUIT_CLOSE, - CIRCUIT_HALF_OPEN, - CIRCUIT_HALF_OPEN_WAIT, - CIRCUIT_OPEN -} from "./src/constants"; +// --- STRATEGIES --- -export declare const MOLECULER_VERSION: string; -export declare const PROTOCOL_VERSION: string; -export declare const INTERNAL_MIDDLEWARES: string[]; +export * as Strategies from "./src/strategies"; -// Below this point are type exports which are part of modules not exported as part of the main index.js file +// --- TRACING --- -export type { CallMiddlewareHandler, Middleware } from "./src/middleware"; +export type { Tracer, Span, TracerOptions } from "./src/tracing"; +export * as TracerExporters from "./src/tracing/exporters"; + +// --- TRANSPORTERS --- + +export * as Transporters from "./src/transporters"; + +// --- VALIDATORS --- +export * as Validators from "./src/validators"; +export type { ValidatorNames } from "./src/validators"; diff --git a/src/runner.d.ts b/src/runner.d.ts index 4242a603a..69b9d4d57 100644 --- a/src/runner.d.ts +++ b/src/runner.d.ts @@ -1,6 +1,6 @@ import ServiceBroker = require("./service-broker"); import Service = require("./service"); -import type { ServiceBrokerOptions } from "./service-broker"; +import type { BrokerOptions } from "./service-broker"; import { Worker } from "cluster"; declare namespace Runner { @@ -72,12 +72,12 @@ declare class Runner { /** * Loaded configuration file */ - configFile: Partial; + configFile: Partial; /** * Merged configuration */ - config: Partial; + config: Partial; /** * Process command line arguments diff --git a/src/service-broker.d.ts b/src/service-broker.d.ts index f09938e11..a749561a0 100644 --- a/src/service-broker.d.ts +++ b/src/service-broker.d.ts @@ -118,7 +118,7 @@ declare namespace ServiceBroker { type SerializerType = SerializerConfig["type"]; - export interface ServiceBrokerOptions { + export interface BrokerOptions { namespace?: string | null; nodeID?: string | null; @@ -322,13 +322,13 @@ declare class ServiceBroker { static INTERNAL_MIDDLEWARES: string[]; - static defaultOptions: ServiceBroker.ServiceBrokerOptions; + static defaultOptions: ServiceBroker.BrokerOptions; MOLECULER_VERSION: string; PROTOCOL_VERSION: string; - options: ServiceBroker.ServiceBrokerOptions; + options: ServiceBroker.BrokerOptions; Promise: PromiseConstructor; @@ -376,7 +376,7 @@ declare class ServiceBroker { runner?: Runner; - constructor(options?: ServiceBroker.ServiceBrokerOptions); + constructor(options?: ServiceBroker.BrokerOptions); registerMiddlewares(userMiddlewares: MiddlewareHandler.Middleware[]): void; registerMoleculerMetrics(): void; diff --git a/src/service-broker.js b/src/service-broker.js index 422f63870..8f6576c8e 100644 --- a/src/service-broker.js +++ b/src/service-broker.js @@ -42,7 +42,7 @@ const C = require("./constants"); * @typedef {import("./service").ServiceDependency} ServiceDependency * @typedef {import("./service").ActionHandler} ActionHandler * @typedef {import("./service-broker")} ServiceBrokerClass - * @typedef {import("./service-broker").ServiceBrokerOptions} ServiceBrokerOptions + * @typedef {import("./service-broker").BrokerOptions} BrokerOptions * @typedef {import("./service-broker").CallingOptions} CallingOptions * @typedef {import("./service-broker").NodeHealthStatus} NodeHealthStatus * @typedef {import("./service-broker").MCallDefinition} MCallDefinition @@ -55,7 +55,7 @@ const C = require("./constants"); /** * Default broker options * - * @type {ServiceBrokerOptions} + * @type {BrokerOptions} */ const defaultOptions = { namespace: "", @@ -190,7 +190,7 @@ class ServiceBroker { /** * Creates an instance of ServiceBroker. * - * @param {ServiceBrokerOptions} options + * @param {BrokerOptions} options * * @memberof ServiceBroker */ diff --git a/src/service.d.ts b/src/service.d.ts index fd80adf57..584b5aaf0 100644 --- a/src/service.d.ts +++ b/src/service.d.ts @@ -40,7 +40,7 @@ declare namespace Service { started?: ServiceAsyncLifecycleHandler | ServiceAsyncLifecycleHandler[]; stopped?: ServiceAsyncLifecycleHandler | ServiceAsyncLifecycleHandler[]; - [name: string]: any; + // [key: string]: any; } export interface ServiceSettingSchema { @@ -49,7 +49,7 @@ declare namespace Service { $dependencyTimeout?: number; $shutdownTimeout?: number; $secureSettings?: string[]; - [name: string]: any; + //[key: string]: any; } export type ServiceAction = < diff --git a/src/tracing/exporters/console.d.ts b/src/tracing/exporters/console.d.ts index ededf4c2e..29bff67c7 100644 --- a/src/tracing/exporters/console.d.ts +++ b/src/tracing/exporters/console.d.ts @@ -8,7 +8,7 @@ import { Color } from "kleur"; declare namespace ConsoleTraceExporter { export interface ConsoleTraceExporterOptions extends BaseTraceExporterOptions { - logger?: Logger; + logger?: Logger | null; colors?: boolean; width?: number; gaugeWidth?: number;