@baseplate-dev/sync
Version:
Library for syncing Baseplate descriptions
70 lines • 2.22 kB
TypeScript
type ArrayKeys<T> = {
[K in keyof T]: T[K] extends unknown[] ? K : never;
}[keyof T];
export interface NonOverwriteableMap<T extends object> {
/**
* Set a value in the map
*
* @param key Key of value in map
* @param value Value to set
*/
set<Key extends keyof T>(key: Key, value: T[Key]): this;
/**
* Prepends a value to an array in the map
*
* @param key Key of value in map
* @param value Array of values to prepend
*/
prepend<Key extends ArrayKeys<T>>(key: Key, value: T[Key] extends (infer U)[] ? U : never): this;
/**
* Appends a value to an array in the map
*
* @param key Key of value in map
* @param value Array of values to append
*/
append<Key extends ArrayKeys<T>>(key: Key, value: T[Key] extends (infer U)[] ? U : never): this;
/**
* Appends an array of values to an array uniquely in the map
*
* @param key Key of value in map
* @param value Array of values to append
*/
appendUnique<Key extends ArrayKeys<T>>(key: Key, value: T[Key] | (T[Key] extends (infer U)[] ? U : never)): this;
/**
* Gets a value from the map
*
* @param key The key of the value to get
*/
get<K extends keyof T>(key: K): T[K] | undefined;
/**
* Merges an object into the map, setting each one of the values in the object
*
* @param value Partial map of data to merge in
*/
merge(value: Partial<T>): this;
/**
* The fully constructed map
*/
value(): T;
}
interface NonOverwriteableMapConfig {
/**
* Keys that contain arrays will be merged together uniquely with defaults
*/
mergeArraysUniquely?: boolean;
/**
* The name of the map to display in errors
*/
name?: string;
/**
* Whether the defaults can be overriden or not
*/
defaultsOverwriteable?: boolean;
}
/**
* Creates map that has an initial default, but whose keys cannot be overwritten
* once written.
*/
export declare function createNonOverwriteableMap<T extends object>(defaults: T, options?: NonOverwriteableMapConfig): NonOverwriteableMap<T>;
export {};
//# sourceMappingURL=non-overwriteable-map.d.ts.map