UNPKG

@httpc/kit

Version:

httpc toolbox for building function-based API with minimal code and end-to-end type safety

44 lines (43 loc) 2.14 kB
export type TokenDefinition = { token: string; fullToken: string | string[]; alias?: string[]; child?: TokenDefinition[]; includes?: string[]; tags?: string[]; }; export declare class PermissionsModel { protected _tokens: TokenDefinition[]; constructor(params?: { tokens?: TokenDefinition[]; }); get tokens(): readonly TokenDefinition[]; find(token: string | readonly string[], level?: "exact" | "partial" | "any"): TokenDefinition | undefined; } type _TokenOf<S extends object> = { [k in keyof S]: S[k]; }[keyof S]; type _TokenAdd<Schema extends object, Token extends string, Builder = undefined> = Schema & { [token in Token]: undefined extends Builder ? Token : Builder extends FluentToken<any, infer T, infer C> ? undefined extends C ? T : `${T}:${C}` : never; }; declare class FluentToken<Schema extends object, Token extends string, Child extends string | undefined = undefined> { protected readonly _token: Token; protected _alias?: Set<string>; protected _includes?: string[]; protected _tags?: Set<string>; protected _fullToken: string[]; protected _child?: TokenDefinition[]; constructor(_token: Token, parent?: string[]); alias<A extends string>(alias: A): this; tag(tag: string | string[]): this; includes<I extends _TokenOf<Schema>>(token: I | I[]): this; token<Sub extends string, Builder extends FluentToken<any, any, any>>(token: Sub, builder?: (token: FluentToken<Schema, Sub>) => Builder): FluentToken<_TokenAdd<Schema, `${Token}:${Sub}`>, Token, Exclude<Child | Sub, undefined>>; build(): TokenDefinition; } declare class FluentPermission<Schema extends object = object> { protected _tokens: TokenDefinition[]; token<Token extends string, Builder extends FluentToken<Schema, Token>>(token: Token, builder?: (token: FluentToken<Schema, Token>) => Builder): FluentPermission<_TokenAdd<Schema, Token, Builder>>; build(): PermissionsModel; } export declare function permissions(api: (builder: FluentPermission) => FluentPermission): PermissionsModel; export {};