import { NameAnd } from "@focuson/utils"; export declare const identityOptics: (description?: string) => Iso; export interface GetOptioner { getOption: (m: Main) => Child | undefined; } export interface SetOptioner { setOption: (m: Main, c: Child) => Main | undefined; } export interface Getter { get: (m: Main) => Child; } export interface Setter { set: (m: Main, c: Child) => Main; } export interface HasOptional { optional: Optional; } /** An Optional is like a lens, except that it is not guaranteed to 'work'. Specifically if you ask for a child... maybe that child isn't there. * * This is great for things like 'optional values' which are often written as 'name?: type' in typescript. * * It is rare that you create one directly. Usually it is created using 'focusQuery' on a lens */ export declare class Optional implements GetOptioner, SetOptioner { getOption: (m: Main) => Child | undefined; setOption: (m: Main, c: Child) => Main | undefined; description: string; constructor(getOption: (m: Main) => (Child | undefined), optionalSet: (m: Main, c: Child) => Main | undefined, description?: string); set: (m: Main, c: Child) => Main; map: (m: Main, fn: (c: Child | undefined) => Child) => Main; mapDefined: (m: Main, fn: (c: Child) => Child) => Main; /** This is identical to this.setOption(m, undefined) */ clearJson(m: Main): Main; /** Allows us to change the focuson-ed child based on it's existing value * @fn a function that will be given the old value and will calculate the new * @returns a function that given a Main will return a new main with the child transformed as per 'fn' */ transform(fn: (oldChild: Child) => Child): (m: Main) => Main; /** This is used when the 'parameter' points to definite value. i.e. it isn't 'x: X | undefined' or 'x?: X'. If you want to * walk through those you probably want to use 'focusQuery' * * If the type system is complaining and you are sure that it should be OK, check if the previous focusOn should be a focusQuery * @param k */ focusOn(k: K): Optional; /** Used to focus onto a child that might not be there. If you don't use this, then the type system is likely to complain if you try and carry on focusing. */ focusQuery>(k: K): Optional; chain(o: Optional): Optional; combine(other: Optional): Optional; /** If you desire to change the description this will do that. It is rarely called outside the Lens code itself */ withDescription(description: string): Optional; combineAs(other: Optional, iso: Iso<[Child, OtherChild], NewChild>): Optional; chainIntoArray(a: string[]): Optional; chainNthFromPath(pathL: Optional): Optional; chainCalc(pathL: Optional): Optional; toString(): string; } export declare function optional(getOption: (m: Main) => Child | undefined, setOption: (m: Main, c: Child) => Main | undefined, description?: string): Optional; export declare function identityOptional
(): Optional; export declare function orUndefined(description?: string): Optional; export declare function castIfOptional(cond: (t: T) => boolean, description?: string): Optional; /** * Creates a lens with two generics. Lens. Main is the main 'object' that we start with, and Child is the part of Main that the lens is focuson-ed * @param get should be a sideeffect free function that goes from 'Main' to the focuson-ed child. When called it 'gets' the Child from the Main * @param set should be a sideeffect free function that creates a new Main out of an old main and a new child. It returns the old main with the 'focuson-ed' part replaced by the new child * @param description should probably be the string representation of the class 'Main'. If the main object is of type Dragon, this could be the string 'dragon'. * * Usually these are created by code like * * identityOptics().focuson('head') */ export declare function lens(get: (main: Main) => Child, set: (main: Main, newChild: Child) => Main, description?: string): Lens; /** This is the class that represents a Lens which focuses on Child which is a part of the Main */ export declare class Lens extends Optional implements Getter, Setter { set: (m: Main, c: Child) => Main; get: (m: Main) => Child; constructor(get: (m: Main) => (Child), set: (m: Main, c: Child) => Main, description: string); /** this is the 'normal' focuson. We use it when we know that the result is there. i.e. if we have * * interface AB{ * a: string, * b?: SomeInterface | undefined * } * * In this case focusOn('a') will give us a Lens but focusOn('b') will give a lens. * @param k */ focusOn(k: K): Lens; /** interface AB{ * a: string, * b?: SomeInterface | undefined * } * * In this case it would be redundant to have focusWithDefault('a', "someA") because 'a' should never be undefined. * However (if someValue is a SomeInterface) focusWithDfeault('b', someValue) return Lens and if we do a get, and b was undefined, we use 'someValue' * @param k */ focusWithDefault>(k: K, def: Child[K]): Lens; chainLens: (o: Lens) => Lens; /** @deprecated */ chainWith: (o: Lens) => Lens; combineLens(other: Lens): Lens; /** If you desire to change the description this will do that. It is rarely called outside the Lens code itself */ withDescription(description: string): Lens; toString(): string; } /** A factory class that allows us to create new Lens. Every method on it is static, so you would never create one of these * * This class will be removed and replaced with just 'plain functions' * */ export declare class Lenses { /** This is a the normal way to generate lens. It create a link that goes from Main to itself */ static build
(description: string): Lens; /** Given a main which is an object, with a field name, this returns a lens that goes from the Main to the contents of the field name */ static field: (fieldName: K) => Lens; /** Given a main which is an object, with a field name, this returns a lens that goes from the Main to the contents of the field name */ static identity(description?: string): Iso; /**This should no longer be needed. It was in fact the need for this method that drove the rewrite using Optionals/Prisms and Isos. * * Nowadays we can use focusQuery * * It should only be used when we 'know' that a Lens is really a Lens. * @deprecated */ static define(): Lens; /** This returns a lens from an array of T to the last item of the array */ static last(): Lens; /** This returns a lens from an array of T to the next item of the array */ static append(): Lens; /** This returns a lens from an array of T to the nth member of the array */ static nth(n: number): Optional; static chainNthFromOptionalFn(lens: Optional, newToFnL: (f: From) => Optional, newFragDescription: string): Optional; static chainNthRef(lens: Optional, lookup: (name: string) => any, name: string, description?: string): Optional; /** Used to to go from ids to values and back again. Obvious if the mapping isn't one to one there will be loss of data */ static chainLookup(opt: Optional, lookupL: Optional>): Optional; /** Used to to go from ids to values and back again. Obvious if the mapping isn't one to one there will be loss of data */ static chainLookupTable(opt: Optional, lookupL: Optional, idName: K, valueName: V): Optional; static constant: (value: Child, description?: string) => Lens; static safeList(): Lens; static if(cond: Optional, trueL: Optional, falseL: Optional): Optional; static condition(cond: Optional, fn: (c: Cond) => boolean, trueL: Optional, falseL: Optional): Optional; static calculatedNth(nL: Optional, opt: Optional): Optional; } export type FocusOnPathItem = string | FocusOnPathSimpleItem | FocusOnPathNthItem | FocusOnPathPathItem; export interface FocusOnPathSimpleItem { action: '$last' | '$append'; } export declare function isFOPSingle(f: FocusOnPathItem): f is FocusOnPathSimpleItem; export interface FocusOnPathNthItem { action: '[n]'; n: number; } export declare function isFOPNth(f: FocusOnPathItem): f is FocusOnPathNthItem; export interface FocusOnPathPathItem { action: '[path]'; path: FocusOnPathItem[]; } export declare function isFOPPath(f: FocusOnPathItem): f is FocusOnPathPathItem; export declare function prism(getOption: (m: Main) => Child | undefined, reverseGet: (c: Child) => Main, description?: string): Prism; export declare function dirtyPrism(getOption: (m: Main) => Child | undefined, reverseGet: (c: Child) => Main, description?: string): DirtyPrism; export declare class DirtyPrism extends Optional { reverseGet: (c: Child) => Main; constructor(getOption: (m: Main) => (Child | undefined), reverseGet: (c: Child) => Main, description: string); toString(): string; } export declare class Prism extends DirtyPrism { constructor(getOption: (m: Main) => (Child | undefined), reverseGet: (c: Child) => Main, description: string); toString(): string; } export declare function iso(get: (m: Main) => Child, reverseGet: (c: Child) => Main, description?: string): Iso; export declare class Iso extends Lens { reverseGet: (c: Child) => Main; optional: Optional; constructor(get: (m: Main) => Child, reverseGet: (c: Child) => Main, description: string); toString(): string; } /** This 'changes' two parts of Main simultaneously. * * @param lens1 This is focused in on a part of main that we want to change * @param lens2 This is focused in on a second part of main that we want to change * @param fn1 Given the old values that lens1 and lens2 are focused on, this gives us a new value for the part of main that lens1 is focused on * @param fn2 Given the old values that lens1 and lens2 are focused on, this gives us a new value for the part of main that lens2 is focused on * @returns a function that given a Main will return a new main with the two functions used to modify the parts of Main that the two lens are focused in on * */ export declare const transformTwoValues: (lens1: Optional, lens2: Optional) => (fn1: (c1: C1, c2: C2) => C1, fn2: (c1: C1, c2: C2) => C2) => (main: Main) => Main; /** This 'changes' two parts of Main simultaneously. * * @param lens1 This is focused in on a part of main that we want to change * @param lens2 This is focused in on a second part of main that we want to change * @param main A value that is to be 'changed' by the method. Changed means that we will make a copy of it with changes * @param c1 The new value for the part that lens1 is focused on * @param c2 The new value for the part that lens2 is focused on * @returns a new main with the parts the two lens are focused on changed by the new values * */ export declare const updateTwoValues: (lens1: Optional, lens2: Optional) => (main: Main, c1: C1, c2: C2) => Main; /** This 'changes' three parts of Main simultaneously. * * @param lens1 This is focused in on a part of main that we want to change * @param lens2 This is focused in on a second part of main that we want to change * @param lens3 This is focused in on a third part of main that we want to change * @param main A value that is to be 'changed' by the method. Changed means that we will make a copy of it with changes * @param c1 The new value for the part that lens1 is focused on * @param c2 The new value for the part that lens2 is focused on * @param c3 The new value for the part that lens3 is focused on * @returns a new main with the parts the three lens are focused on changed by the new values * */ export declare const updateThreeValues: (lens1: Optional, lens2: Optional, lens3: Optional) => (main: Main, c1: C1, c2: C2, c3: C3) => Main; export declare function nthItem(n: number): Optional; export declare function firstIn2(): Optional<[T1, T2], T1>; export declare function secondIn2(): Optional<[T1, T2], T2>; export type Transform = [Optional, (c: Child | undefined) => Child]; interface DisplayTransform { opt: string; value: any; } export declare function displayTransformsInState(main: S, txs: Transform[]): DisplayTransform[]; export declare function massTransform
(main: Main, ...transforms: Transform[]): Main; export declare function nameLensFn>(lens: Optional): GetNameFn; export declare function asGetNameFn(nl: NameAndLens): GetNameFn; export type GetNameFn = (name: string) => GetOptioner; export interface NameAndLens { [name: string]: Optional; } export interface NameAndLensFn { [name: string]: (o: Iso) => Optional; } export {};