Definitions#

These TypeScript definitions document server validation. check.object rejects unknown fields. Custom functions and refinements specify additional checks.

Imported definitions#

Operation#

export type Operation<Params, Query, Input, Output> = {
    method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
    path: string;
    auth: 'public' | 'human' | 'agent' | 'either' | 'fleet';
    params: Parser<Params>;
    query: Parser<Query>;
    input: Parser<Input>;
    output: Parser<Output>;
    status: 200 | 201 | 202;
    collection: boolean;
    permissions: readonly string[];
    description: string;
    requestBytes?: number;
    requestFormat?: 'binary';
};

Related definitions:

operation#

export function operation<Params, Query, Input, Output>(definition: Operation<Params, Query, Input, Output>): Operation<Params, Query, Input, Output> { return definition; }

Related definitions:

ParamsOf#

export type ParamsOf<Value extends {
    params: Parser<unknown>;
}> = Parsed<Value['params']>;

Related definitions:

QueryOf#

export type QueryOf<Value extends {
    query: Parser<unknown>;
}> = Parsed<Value['query']>;

Related definitions:

InputOf#

export type InputOf<Value extends {
    input: Parser<unknown>;
}> = Parsed<Value['input']>;

Related definitions:

OutputOf#

export type OutputOf<Value extends {
    output: Parser<unknown>;
}> = Parsed<Value['output']>;

Related definitions:

operationPath#

export function operationPath(path: string, params: Record<string, string>): string {
    return path.replace(/\{([A-Za-z]+)\}/gu, (_match: string, key: string) => {
        const value = params[key];
        if (value === undefined)
            throw new Error('Missing route parameter: ' + key);
        return encodeURIComponent(value);
    });
}