UNPKG

@altostra/core

Version:

Core library for shared types and logic

39 lines (38 loc) 1.98 kB
import type { ResourceId, ResourceType } from "./Blueprint"; /** * An object that identify a unique set of strings. \ * This object may be a `Set` of strings, or simply and object, where its keys are being th unique set */ export declare type StringsSet = Record<ResourceId, unknown> | Set<ResourceId>; /** * Manages resource-ids across a blueprint (or anything that needs unique set of ids) */ export declare class ResourceIdsManager { private readonly _resourceNamesSet; private readonly _highestNameCounter; /** * Initialize new instance of `ResourceIdsManager` * @param resourceNamesSet A strings set, which is either an object (having its keys as set of strings) * Or a Set of strings */ constructor(resourceNamesSet: StringsSet); /** * Generates unique id for a resource * @param name The name of the resource for which a new unique id is required * @param resourceType The type of the resource for which a new unique id is required * @param dontRegisterName Optional boolean \ * If `true` the name and counter (postfix) won't be registered, meaning they must be added to * the provided set before the next id is request, and it would be less efficiently generated \ * Otherwise (`false`, `undefined`, or simply omitted) - the name and counter would be registered * for efficient id generation * @returns A new unique resource id */ getIdFromName(name: string, resourceType: ResourceType, dontRegisterName?: boolean): ResourceId; /** * Register and name and counter for efficient generation of unique ids * @param name If a `counter` is provided, this is the *raw name* (a name without counter appended to it); \ * Otherwise, this is the name with optional number appended to it, for registration * @param highestCounter An optional counter to be registered alongside the name */ registerName(name: string, highestCounter?: number): void; }