95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
import { syscall } from "../syscall.ts";
|
|
|
|
/**
|
|
* Gets a config value by path, with support for dot notation.
|
|
* @param path The path to get the value from
|
|
* @param defaultValue The default value to return if the path doesn't exist
|
|
* @returns The value at the path, or the default value
|
|
*/
|
|
export function get<T>(path: string | string[], defaultValue: T): Promise<T> {
|
|
return syscall("config.get", path, defaultValue);
|
|
}
|
|
|
|
/**
|
|
* Sets a config value by path, with support for dot notation.
|
|
* @param path The path to set the value at
|
|
* @param value The value to set
|
|
*/
|
|
export function set<T>(path: string, value: T): Promise<void>;
|
|
/**
|
|
* Sets multiple config values at once.
|
|
* @param values An object containing key-value pairs to set
|
|
*/
|
|
export function set(values: Record<string, any>): Promise<void>;
|
|
export function set<T>(
|
|
pathOrValues: string | Record<string, any>,
|
|
value?: T,
|
|
): Promise<void> {
|
|
return syscall("config.set", pathOrValues, value);
|
|
}
|
|
|
|
/**
|
|
* Inserts a config value into an array
|
|
*/
|
|
export function insert<T>(path: string | string[], value: T): Promise<void> {
|
|
return syscall("config.insert", path, value);
|
|
}
|
|
|
|
/**
|
|
* Checks if a config path exists.
|
|
* @param path The path to check
|
|
* @returns True if the path exists, false otherwise
|
|
*/
|
|
export function has(path: string): Promise<boolean> {
|
|
return syscall("config.has", path);
|
|
}
|
|
|
|
/**
|
|
* Defines a JSON schema for a configuration key.
|
|
* The schema will be used to validate values when setting this key.
|
|
* @param key The configuration key to define a schema for
|
|
* @param schema The JSON schema to validate against
|
|
*/
|
|
export function define(key: string, schema: any): Promise<void> {
|
|
return syscall("config.define", key, schema);
|
|
}
|
|
|
|
/**
|
|
* Defines (or updates) a UI category for the configuration manager. Categories
|
|
* are referenced by name from a schema field's `ui.category` and are sorted in
|
|
* ascending `order` (default 0); unknown categories fall to the bottom in
|
|
* alphabetical order.
|
|
*/
|
|
export function defineCategory(definition: {
|
|
name: string;
|
|
description?: string;
|
|
order?: number;
|
|
}): Promise<void> {
|
|
return syscall("config.defineCategory", definition);
|
|
}
|
|
|
|
/**
|
|
* Gets all config values as a single object.
|
|
* @returns The entire config values object
|
|
*/
|
|
export function getValues(): Promise<Record<string, any>> {
|
|
return syscall("config.getValues");
|
|
}
|
|
|
|
/**
|
|
* Gets all defined config schemas.
|
|
* @returns The schema definitions object
|
|
*/
|
|
export function getSchemas(): Promise<Record<string, any>> {
|
|
return syscall("config.getSchemas");
|
|
}
|
|
|
|
/**
|
|
* Gets all registered UI categories for the configuration manager.
|
|
*/
|
|
export function getCategories(): Promise<
|
|
Record<string, { name: string; description?: string; order?: number }>
|
|
> {
|
|
return syscall("config.getCategories");
|
|
}
|