import type { TuplePaths } from '@baseplate-dev/utils'; import type { RefContextSlot } from './ref-context-slot.js'; import type { DefinitionEntity, DefinitionEntityType, DefinitionReference } from './types.js'; /** * Allows the caller to resolve the name of an entity, optionally providing a * map of entity ids that need to be resolved prior to resolving the entity's * name. */ export interface DefinitionEntityNameResolver = Record> { /** * Optional map of entity ids that need to be resolved prior to resolving the * entity's name. */ idsToResolve?: TEntityIds; /** * Resolves the name of an entity from the provided entity names. * @param entityNames - A map of entity ids to their names. * @returns The name of the entity. */ resolveName: (entityNames: TEntityIds) => string; } /** * Creates a definition entity name resolver. * @param entityNameResolver - The entity name resolver. * @returns The definition entity name resolver. */ export declare function createDefinitionEntityNameResolver>(entityNameResolver: DefinitionEntityNameResolver): DefinitionEntityNameResolver; /** * Base definition for entity input. * * @template TInput - The overall input data type. * @template TEntityType - The entity type, extending DefinitionEntityType. * @template TPath - The type representing a path in TInput (e.g. a dot-separated string); defaults to undefined. * @template TIdKey - The key type for the entity's id; defaults to "id". */ interface DefinitionEntityInputBase | undefined = undefined> { /** The entity type definition. */ type: TEntityType; /** Optional path key used to store the entity's id; if not provided, the id is assumed to be under the entity's path with key "id". */ idPath?: TIdPath; /** Optional function used to get the name resolver from the input data. Otherwise, the entity's name is assumed to be under the entity's path with key "name". */ getNameResolver?: (value: TInput) => DefinitionEntityNameResolver | string; /** Optional ref context slot that this entity provides. Registers this entity's path in a shared context. */ provides?: RefContextSlot; /** When true, arrays of this entity type are sorted by name during serialization for deterministic output. */ sortByName?: boolean; } /** * Entity input when a parent reference is required. */ interface DefinitionEntityInputWithParent | undefined = undefined> extends DefinitionEntityInputBase { /** The slot from which to resolve the parent entity path. */ parentSlot: RefContextSlot>; } /** * Entity input when no parent reference is expected. */ interface DefinitionEntityInputWithoutParent | undefined = undefined> extends DefinitionEntityInputBase { parentSlot?: never; } /** * Depending on the entity type’s requirements, this type resolves to either the * with- or without-parent version. */ export type DefinitionEntityInput | undefined = undefined> = TEntityType['parentType'] extends undefined ? DefinitionEntityInputWithoutParent : DefinitionEntityInputWithParent; /** * Base interface for defining a reference input. * @template TInput - The overall input type. * @template TEntityType - The entity type. */ interface DefinitionReferenceInputBase extends Pick { type: TEntityType; /** Optional ref context slot that this reference provides. Registers this reference's path in a shared context. */ provides?: RefContextSlot; } interface DefinitionReferenceInputWithParent extends DefinitionReferenceInputBase { /** The slot from which to resolve the parent entity path. */ parentSlot: RefContextSlot>; } interface DefinitionReferenceInputWithoutParent extends DefinitionReferenceInputBase { parentSlot?: never; } /** * Depending on the entity type’s requirements, defines the input required to create a definition reference. */ export type DefinitionReferenceInput = TEntityType['parentType'] extends undefined ? DefinitionReferenceInputWithoutParent : DefinitionReferenceInputWithParent; /** * Entity with a name resolver. */ export interface DefinitionEntityWithNameResolver extends Omit { nameResolver: DefinitionEntityNameResolver | string; } export {}; //# sourceMappingURL=definition-ref-builder.d.ts.map