import { sortedMap, SortedMultiMap } from './sorted-map'; export interface Entity { readonly $id: string; } export type Plain = Omit; type Indexes = { [K in PropertyKey]: EntityIndex; }; export interface EntityCollection = {}> { readonly type: 'entities'; readonly entities: Map; readonly indexes: I; add(x: A): void; dehydrate(): any; hydrateFrom(x: any): void; /** * Add indexes to this collection * * Creating an indexed collection is a two-step operation so that we can specify the * Entity type, but infer the index types (TypeScript does not allow both specifying AND * inferring generic arguments in a single call). */ index>(indexes: II): EntityCollection; } /** * Interface for index objects */ export interface EntityIndex { /** * The lookups that the indexed field type affords * * For example, 'equals', 'lessThan', 'prefix', etc. */ readonly lookups: IndexLookups; /** * The index data store */ readonly index: SortedMultiMap; /** * Add an entity to the index */ add(x: A): void; } /** * Map a type the types of lookups we can do on that type */ export type IndexLookups

= [P] extends [string] ? StringIndexLookups : [P] extends [string | undefined] ? OptionalStringIndexLookups : {}; /** * All the lookups on 'string' types * * We currently only have 'equals' but we could have more :) */ export interface StringIndexLookups { equals(x: string): string[]; } /** * All the lookups on 'string | undefined' types */ export interface OptionalStringIndexLookups { equals(x: string | undefined): string[]; } export declare function entityCollection(): EntityCollection; /** * An index that uses the value of an entity's field */ export declare function fieldIndex(propName: P, comparator: sortedMap.Comparator): EntityIndex; /** * An index that is calculated based on a function applied to an entity */ export declare function calculatedIndex(fn: (x: A) => B, comparator: sortedMap.Comparator): { add: (x: A) => void; lookups: any; index: SortedMultiMap; }; export declare function isEntityCollection(x: unknown): x is EntityCollection; export interface Reference { readonly $ref: E['$id']; } export declare function ref(x: E | string): Reference; /** * Determines whether two strings are equivalent in the current or specified locale. */ export declare function stringCmp(a: string, b: string): number; /** * Determines whether two numbers are equivalent. */ export declare function numberCmp(a: number, b: number): number; /** * Creates a comparator to determine equivalent of two values, using a given comparator, but allows values to be optional. * * @param frontOrder If `true`, returns so that undefined values are ordered at the front. If `false`, undefined values are ordered at the back. */ export declare function optionalCmp(cmp: (a: A, b: A) => number, frontOrder?: boolean): (a: A | undefined, b: A | undefined) => number; export {};