Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General improvements to type docs #625

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build
deps
docs
types/api
examples
tests
src/bundles
154 changes: 75 additions & 79 deletions types/src/txikijs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ declare global {
/**
* Array with the arguments passed to the binary.
*/
const args: string[];
const args: readonly string[];

type Signal = 'SIGHUP' | 'SIGINT' | 'SIGQUIT' | 'SIGILL' | 'SIGTRAP'
| 'SIGABRT' | 'SIGBUS' | 'SIGFPE' | 'SIGKILL' | 'SIGUSR1' | 'SIGSEGV'
Expand Down Expand Up @@ -103,30 +103,13 @@ declare global {
* @param sig The name of the signal to send. Defaults to "SIGTERM".
*/
function kill(pid: number, sig?: Signal): void;

/**
* Management for the garbage collection.
*/
interface IGarbageCollection {
/**
* Force garbage collection now.
*/
run: () => void;

/**
* Enables / disables automatic garbage collection.
*/
enabled: boolean;

/**
* Sets / gets the threshold (in bytes) for automatic garbage collection.
*/
threshold: number;
}

type CompiledCode = unknown;

interface IEngine {
/** @namespace
*
*/
const engine : {
/**
* Compiles the provided code into bytecode ready to be evaluated or serialized.
*
Expand Down Expand Up @@ -160,26 +143,39 @@ declare global {
evalBytecode: (code: CompiledCode) => Promise<unknown>;

/**
* Garbage collection management.
*/
gc: IGarbageCollection;
* Management for the garbage collection.
*/
readonly gc: {
/**
* Force garbage collection now.
*/
run: () => void;

/**
* Enables / disables automatic garbage collection.
*/
enabled: boolean;

/**
* Sets / gets the threshold (in bytes) for automatic garbage collection.
*/
threshold: number;
}

/**
* Versions of all included libraries and txiki.js itself.
*/
versions: {
quickjs: string;
tjs: string;
uv: string;
curl: string;
wasm3: string;
sqlite3: string;
mimalloc?: string;
readonly versions: {
readonly quickjs: string;
readonly tjs: string;
readonly uv: string;
readonly curl: string;
readonly wasm3: string;
readonly sqlite3: string;
readonly mimalloc?: string;
};
}

const engine: IEngine;

/**
* The txiki.js version.
*/
Expand Down Expand Up @@ -756,90 +752,90 @@ declare global {
*/
const ppid: number;

interface UserInfo {
userName: string;
userId: number;
gorupId: number;
shell: string | null;
homeDir: string | null;
}

interface CpuTimes {
user: number;
nice: number;
sys: number;
idle: number;
irq: number;
}

interface CpuInfo {
model: string;
speed: number;
times: CpuTimes;
}

interface NetworkInterface {
name: string;
address: string;
mac: string;
scopeId?: number;
netmask: string;
internal: boolean;
namespace system{
interface UserInfo {
userName: string;
userId: number;
gorupId: number;
shell: string | null;
homeDir: string | null;
}

interface CpuTimes {
user: number;
nice: number;
sys: number;
idle: number;
irq: number;
}

interface CpuInfo {
model: string;
speed: number;
times: CpuTimes;
}

interface NetworkInterface {
name: string;
address: string;
mac: string;
scopeId?: number;
netmask: string;
internal: boolean;
}
}

interface ISystem {
/** @namespace
* System information.
*/
const system: {
/**
* Machine architecture.
*/
arch: string;
readonly arch: string;

/**
* An estimate of the default amount of parallelism a program should use.
*/
availableParallelism: number;
readonly availableParallelism: number;

/**
* Information about the CPUs in the system.
*/
cpus: CpuInfo[];
readonly cpus: system.CpuInfo[];

/**
* System load average.
* See [getloadavg(3)](https://man7.org/linux/man-pages/man3/getloadavg.3.html)
*/
loadAvg: [ number, number, number ];
readonly loadAvg: [ number, number, number ];

/**
* Information about the network interfaces in the system.
*/
networkInterfaces: NetworkInterface[];
readonly networkInterfaces: system.NetworkInterface[];

/**
* Operating System kernel version.
*/
osRelease: string;
readonly osRelease: string;

/**
* Current platform.
*/
platform: 'linux' | 'darwin' | 'windows';
readonly platform: 'linux' | 'darwin' | 'windows';

/**
* System uptime.
*/
uptime: number;
readonly uptime: number;

/**
* Current user information from the password database.
*/
userInfo: UserInfo;
readonly userInfo: system.UserInfo;
}

/**
* System information.
*/
const system: ISystem;

interface ConsolePrinterOptions {
/** output message to stderr instead of stdout */
isWarn?: boolean;
Expand Down
Loading