import { MessageLocation } from '../validation/location.js'; import type { Field } from './field.js'; import { Index } from './indices.js'; import type { RootEntityType } from './root-entity-type.js'; import type { TimeToLiveType } from './time-to-live.js'; import type { VectorIndex } from './vector-index.js'; /** * Describes which part of the model requires an index */ export type IndexOrigin = KeyIndexOrigin | FieldDirectiveIndexOrigin | RootEntityIndicesIndexOrigin | TimeToLiveIndexOrigin | DiscriminatorIndexOrigin | VectorIndexOrigin; interface IndexOriginBase { readonly rootEntityType: RootEntityType; /** * The location in the sources of the construct that requires the index, if available */ readonly location: MessageLocation | undefined; } interface PersistentIndexOriginBase extends IndexOriginBase { readonly index: Index; } /** * The unique index that is created for the field marked with @key * * This index is sparse (like all unique indices without an explicit sparse: false), so it can't be * used for sorting. */ export interface KeyIndexOrigin extends PersistentIndexOriginBase { readonly kind: 'key'; readonly field: Field; } /** * An index declared with @index or @unique on a field of a root entity type */ export interface FieldDirectiveIndexOrigin extends PersistentIndexOriginBase { readonly kind: 'fieldDirective'; readonly field: Field; } /** * An index declared in the "indices" argument of @rootEntity */ export interface RootEntityIndicesIndexOrigin extends PersistentIndexOriginBase { readonly kind: 'rootEntityIndices'; } /** * The index on the date field of a time-to-live configuration */ export interface TimeToLiveIndexOrigin extends PersistentIndexOriginBase { readonly kind: 'timeToLive'; readonly timeToLiveType: TimeToLiveType; } /** * The index on the discriminator field (id) that cruddl adds so it can sort by it */ export interface DiscriminatorIndexOrigin extends PersistentIndexOriginBase { readonly kind: 'discriminator'; readonly field: Field; } /** * A vector index declared with @vectorIndex on a field */ export interface VectorIndexOrigin extends IndexOriginBase { readonly kind: 'vectorIndex'; readonly field: Field; readonly vectorIndex: VectorIndex; } export type PersistentIndexOrigin = Exclude; export interface IndexWithOrigin { readonly index: Index; readonly origin: PersistentIndexOrigin; } /** * Gets the indices of a root entity type (including those cruddl adds implicitly), together with * the part of the model they come from * * If multiple parts of the model require the same index, the index is only included once, with the * origin that comes first in this order: explicitly declared indices, @key, time-to-live, * discriminator. */ export declare function getIndicesWithOrigins(rootEntityType: RootEntityType): ReadonlyArray; export {};