@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
63 lines (62 loc) • 3.07 kB
TypeScript
import { Primitive } from '../types/Primitive';
import { Constructor } from '../types/Constructor';
import { PageList } from '../types/PageList';
import { List } from '../types/List';
import { Get } from '../types/Get';
import { DontInfer } from '../types/Types';
import { AnyKey } from '../types/AnyKey';
import { EnumConstructor } from '../types/Enum';
type Func<T = unknown> = (a: any, key?: string) => T;
type FuncOn<S> = (a: S, key?: string) => unknown;
type Viewer = {
key: string;
f: Func;
};
type ViewType<V = any> = Primitive | EnumConstructor | Constructor | Func | View<V> | undefined;
type ViewValue<S = never> = [S] extends [never] ? ViewType : Exclude<ViewType, string | Func> | AnyKey<S> | FuncOn<S>;
type ViewRecord<V = any, S = never> = [S] extends [never] ? Partial<Record<keyof V | typeof spread, ViewValue<S>>> : Partial<Record<keyof V | typeof spread, ViewValue<S>>> & Partial<Record<Exclude<Extract<keyof S, string>, Extract<keyof V, string>>, typeof ignore>>;
declare const ignore: unique symbol;
declare const keep: unique symbol;
declare const json: unique symbol;
declare const spread = "view.spread";
export declare const toViewer: (key: string, value: ViewType) => Viewer;
export declare class View<V = any, S = never> {
private views;
readonly startsFrom: 'scratch' | 'source';
readonly viewers: Viewer[];
private spreads;
constructor(views?: ViewRecord<V, S>, startsFrom?: 'scratch' | 'source', viewers?: Viewer[], spreads?: Get<V>[]);
get fromSource(): View<V, S>;
spread(f: Get<V>): View<V, S>;
from<T = unknown>(source: PageList<T>): PageList<V>;
from<T = unknown>(source: List<T>): List<V>;
from<T = unknown>(source: T[]): V[];
from<T = unknown>(source: T): V;
same: (one?: unknown, another?: unknown) => boolean;
private reduce;
}
export declare const isSimpleView: (a: unknown) => a is View;
export declare const view: <V = any, S = never>(views: ViewRecord<DontInfer<V>, DontInfer<S>>) => View<V, S>;
export declare const views: {
readonly ignore: typeof ignore;
readonly keep: typeof keep;
readonly json: typeof json;
readonly spread: "view.spread";
readonly skip: typeof ignore;
readonly equals: (key: string, value: unknown) => (a: unknown) => boolean;
readonly value: (value: unknown) => () => unknown;
readonly coalesce: (...keys: string[]) => (a: unknown) => unknown;
readonly or: {
readonly key: (altKey: string) => (a: unknown, key?: string) => unknown;
readonly value: (altValue: unknown) => (a: unknown, key?: string) => unknown;
readonly func: (altFunc: Func) => (a: unknown, key?: string) => unknown;
};
readonly to: <T = unknown>(ctorOrFunc: Constructor<T> | ((v: any) => T)) => ((a: any, key?: string) => T | undefined) & {
or: {
key: (altKey: string) => (a: unknown, key?: string) => unknown;
value: (altValue: T) => (a: unknown, key?: string) => T;
func: (altFunc: Func) => (a: unknown, key?: string) => unknown;
};
};
};
export {};