type GetIndexedField = K extends keyof T ? T[K] : K extends `${number}` ? '0' extends keyof T ? undefined : number extends keyof T ? T[number] : undefined : undefined; type FieldWithPossiblyUndefined = GetFieldType, Key> | Extract; type IndexedFieldWithPossiblyUndefined = GetIndexedField, Key> | Extract; type GetFieldType = P extends `${infer Left}.${infer Right}` ? Left extends keyof T ? FieldWithPossiblyUndefined : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined : undefined : undefined; declare class ObjectProducer { entity: TEntity; constructor(entity: TEntity); get(propPath: TPath): GetFieldType; set(propPath: TPath, value: GetFieldType): TEntity; } type Id = string | number; type Ids = Id[]; type IdOrIds = Id | Ids; interface EntityAddOptions { prepend?: boolean; afterId?: Id; } interface EntityMoveOptions { afterId?: Id; toIndex?: number; } type ExtractKeysOfValueType = { [I in keyof T]: T[I] extends K ? I : never; }[keyof T]; interface ProducerOptions { idKey?: ExtractKeysOfValueType; } declare class Producer { private idKey; private entities; constructor(entities: TEntity[], options?: ProducerOptions); private getPathValue; /** * Add an entity or entities. * * @example * produce([users]).add(Entity); * produce([users]).add([Entity, Entity]); * produce([users]).add(Entity, { prepend: true }); * produce([users]).add(Entity, { afterId: '' }); */ add(entity: TEntity | TEntity[], addOptions?: EntityAddOptions): TEntity[]; /** * * Update an entity or entities. * * @example * produce([users]).update(3, { * name: 'New Name' * }); * * produce([users]).update(3, entity => { * return { * ...entity, * name: 'New Name' * } * }); * * produce([users]).update([1,2,3], { * name: 'New Name' * }); */ update(id: IdOrIds | null, newStateFn: (entity: Readonly) => Partial): TEntity[]; update(id: IdOrIds | null, newState?: Partial): TEntity[]; /** * * Remove one or more entities: * * @example * produce([users]).remove(5); * produce([users]).remove([1,2,3]); * produce([users]).remove(entity => entity.id === 1); */ remove(id: IdOrIds): TEntity[]; remove(predicate: (entity: Readonly) => boolean): TEntity[]; /** * * Move one or more entities: * * @example * produce([users]).move(5, {afterId: 2}); * produce([users]).move(5, {toIndex: 0}); */ move(id: Id, moveOptions?: EntityMoveOptions): TEntity[]; } declare function produce(entities: TEntity[], options?: ProducerOptions): Producer; declare function produce(entities: TEntity): ObjectProducer; export { ObjectProducer, Producer, produce }; export type { EntityAddOptions, EntityMoveOptions, Id, IdOrIds, Ids, ProducerOptions };