@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
74 lines (73 loc) • 2.38 kB
TypeScript
import { Text } from './Text';
import { List } from './List';
import { Optional } from './Types';
import { OneOrMore } from './Array';
export type Segment = Text & {
key?: string;
segment?: string;
query?: (value: unknown) => string;
};
export declare const toSegment: (key?: Text, { segment, query, }?: {
segment?: string;
query?: (value: unknown) => string;
}) => Segment;
export declare const uri: {
host: (key?: string) => Segment;
resource: <Props extends UriExpandProps>(resource: Uri<Props>) => Segment;
segment: (key?: Text) => Segment;
path: (key: Text) => Segment;
query: (key: Text) => Segment;
boolean: (key: Text) => Segment;
};
type Prop = {
segment: Segment;
value: any;
};
export type Uri<Props extends UriExpandProps = UriExpandProps> = {
id: (id?: unknown) => Uri<Props>;
ids: (ids: OneOrMore<unknown>) => Uri<Props>;
query: (q?: unknown) => Uri<Props>;
sort: (q?: any) => Uri<Props>;
skip: (n?: number) => Uri<Props>;
take: (n?: number) => Uri<Props>;
path: string;
route: (resource: string) => string;
isInternal: boolean;
toString: () => string;
expand: (props: Partial<Props>) => Uri<Props>;
};
export type UriExpandProps = {
q?: string;
s?: string;
skip?: number;
take?: number;
};
export declare class EasyUri<Props extends UriExpandProps = UriExpandProps> implements Uri<Props> {
readonly segments: Segment[];
static readonly id: Segment;
static readonly ids: Segment;
static readonly query: Segment;
static readonly sort: Segment;
static readonly skip: Segment;
static readonly take: Segment;
readonly host: Segment;
protected resource: Segment;
protected state: any;
constructor(segments?: Segment[]);
get path(): string;
get complete(): string;
get isInternal(): boolean;
protected get props(): List<Prop>;
route: (resource?: Optional<string>) => string;
set: (segment: Segment, value?: unknown) => this;
toString(): string;
id: (id?: unknown) => this;
ids: (ids: OneOrMore<unknown>) => this;
query: (q?: unknown) => this;
sort: (s?: any) => this;
skip: (index?: number) => this;
take: (items?: number) => this;
expand(props: Partial<Props>): this;
}
export declare const clipUri: (uri?: EasyUri | string | null) => string;
export {};