Skip to content

Core Types

This file defines the foundational TypeScript types and interfaces used throughout the @sodacore/core framework. These types provide strong typing for configuration, plugins, hooks, workers, tasks, commands, threading, scripting, logging, and more.


Types

Constructor

typescript
export type Constructor<K> = { new(): K };

A generic type for class constructors.


Hooks & Logging

typescript
export type IHookType = 'preInit' | 'postInit' | 'preStart' | 'postStart' | 'preStop' | 'postStop' | string;
export type ILoggerType = 'info' | 'warn' | 'error';

Defines valid hook and logger event types.


Configuration

typescript
export type IConfig = {
	name?: string,
	logger?: Logger,
	autowire?: boolean,
	basePath?: string,
	enableCli?: boolean,
	password?: string,
	hostname?: string,
	port?: number,
};

Main application configuration options.


Service Queue

typescript
export type IConfigServiceQueue = {
	enabled: boolean,
	hostname?: string,
	port: number,
};

Configuration for service queues.


Autowire Module

typescript
export type IAutowireModule = {
	name: string,
	type: string,
	order: number,
	module: any,
};

Metadata for modules registered via autowiring.


Plugin Interface

typescript
export interface IPlugin {
	name: string,
	version: string,
	description: string,
	author: string,
	dependencies: string[],
	install?: (app: Application) => Promise<void>,
	init?: () => Promise<any>,
	start?: () => Promise<any>,
	stop?: () => Promise<any>,
}

Defines the structure for plugins.


Task & Worker Types

typescript
export type ITaskSettings = {
	name?: string,
	maxRuns?: number,
	timezone?: string,
	startAt?: Date,
	stopAt?: Date,
	interval?: number,
	protect?: boolean,
};

export type IWorkerOptions = {
	uid?: string,
	poolSize?: number,
};

export type IWorkerControllerItem = {
	uid: string,
	uidShort: string,
	filename: string,
	options: IWorkerOptions,
	instance: any,
	queue: IWorkerQueueItem[],
	workers: {
		worker: Worker,
		active: boolean,
		ready: boolean,
		item: IWorkerQueueItem | null,
	}[],
};

export type IWorkerQueueItem = {
	uid: string,
	timeout: NodeJS.Timeout | null,
	createdAt: number,
	workerId?: number,
	data: { method: string, params: any[] },
	resolve: (value: unknown) => void,
	reject: (value: unknown) => void,
};

export type IWorkerMessage = {
	id: string,
	command?: string,
	method?: string,
	args?: any[],
};

Types for task scheduling and worker management.


Threading Types

typescript
export type IThreadMessage = {
	uid?: string,
	command: string,
	context?: Record<string, any>,
	isResult?: boolean,
};

export type IThreadQueueItem = {
	resolve: (value: unknown) => void,
	timeout: number,
	command: string,
	context?: Record<string, any>,
};

export type IThreadQueueItemWithMeta = IThreadQueueItem & {
	createdAt: number,
};

export interface IThreadController {
	[key: string | number | symbol]: (context: ThreadContext) => Promise<any>,
}

Types for thread messaging and queue management.


Command Types

typescript
export type ITaskType = 'manual' | 'scheduled' | 'any';

export type ICommandsMeta = ICommandOptionsWithMeta[];

export type ICommandOptions = {
	name?: string,
	description?: string,
	hidden?: boolean,
};

export type ICommandOptionsWithMeta = ICommandOptions & {
	name: string,
	func: string | symbol,
};

export type ICommandParamOptions = {
	description?: string,
	default?: string,
	example?: string,
};

export type ICommandNamespaceOptions = {
	name?: string,
	description?: string,
	hidden?: boolean,
};

Types for command metadata and options.


Packet & Response Types

typescript
export type IPacket = {
	command: string,
	context?: Record<string, any>,
	result?: {
		status: boolean,
		message?: string,
		error?: Error,
		toMenu?: boolean,
	},
};

export type IResponse = {
	status: boolean,
	message?: string,
	error?: Error,
	context?: Record<string, any>,
};

Types for communication packets and responses.


Scripting Types

typescript
export type IScriptSocketData = {
	uid: symbol,
	authenticated: boolean,
	results: Record<string, (value: any) => void>,
	session: Map<string, any>,
	userDefined: Record<string, any>,
	onExit: Array<() => void>,
};

export type IScriptMetaParamItem = {
	type: 'socket' | 'context',
	index: number,
	key?: string | boolean,
};

export type AsScript<T> = {
	[key in keyof T]: T[key] extends Function ? (context: ScriptContext) => any | Promise<any> : T[key]
};

export type IScriptPromptItem = {
	type: 'text' | 'confirm' | 'select' | 'multiselect',
	key: string,
	options: TextOptions | ConfirmOptions | SelectOptions<any> | MultiSelectOptions<any>,
};

Types for scripting context, parameters, and prompts.


Logging

typescript
export type ILogMessage = {
	type: ILoggerType,
	message: string,
	formatted: string,
};

Structure for log messages.


Utility

typescript
export type MaybePromise<T> = T | Promise<T>;

A utility type for values that may be synchronous or asynchronous.


Notes

  • These types are intended for internal use by the Sodacore core framework but can be imported for custom modules, plugins, or advanced scripting.
  • They provide strong typing and IntelliSense support for all major framework features, including plugins, workers, tasks, commands, and scripting.

Released under the Apache-2.0 License.