elysia
Version:
Ergonomic Framework for Human
87 lines (86 loc) • 2.8 kB
TypeScript
import type { Handler, HookContainer, LifeCycleStore } from './types';
export declare namespace Sucrose {
interface Inference {
query: boolean;
headers: boolean;
body: boolean;
cookie: boolean;
set: boolean;
server: boolean;
route: boolean;
request: boolean;
}
interface LifeCycle extends Partial<LifeCycleStore> {
handler?: Handler;
}
}
export declare const hasReturn: (fn: string | HookContainer<any> | Function) => any;
/**
* Separate stringified function body and paramter
*
* @example
* ```typescript
* separateFunction('async ({ hello }) => { return hello }') // => ['({ hello })', '{ return hello }']
* ```
*/
export declare const separateFunction: (code: string) => [string, string, {
isArrowReturn: boolean;
}];
/**
* Get range between bracket pair
*
* @example
* ```typescript
* bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
* ```
*/
export declare const bracketPairRange: (parameter: string) => [number, number];
/**
* Similar to `bracketPairRange` but in reverse order
* Get range between bracket pair from end to beginning
*
* @example
* ```typescript
* bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
* ```
*/
export declare const bracketPairRangeReverse: (parameter: string) => [number, number];
export declare const removeColonAlias: (parameter: string) => string;
/**
* Retrieve only root paramters of a function
*
* @example
* ```typescript
* retrieveRootParameters('({ hello: { world: { a } }, elysia })') // => {
* parameters: ['hello', 'elysia'],
* hasParenthesis: true
* }
* ```
*/
export declare const retrieveRootParamters: (parameter: string) => {
hasParenthesis: boolean;
parameters: string[];
};
/**
* Find inference from parameter
*
* @param parameter stringified parameter
*/
export declare const findParameterReference: (parameter: string, inference: Sucrose.Inference) => string;
/**
* Find alias of variable from function body
*
* @example
* ```typescript
* findAlias('body', '{ const a = body, b = body }') // => ['a', 'b']
* ```
*/
export declare const findAlias: (type: string, body: string, depth?: number) => string[];
export declare const extractMainParameter: (parameter: string) => string | undefined;
/**
* Analyze if context is mentioned in body
*/
export declare const inferBodyReference: (code: string, aliases: string[], inference: Sucrose.Inference) => string[];
export declare const removeDefaultParameter: (parameter: string) => string;
export declare const isContextPassToFunction: (context: string, body: string, inference: Sucrose.Inference) => boolean;
export declare const sucrose: (lifeCycle: Sucrose.LifeCycle, inference?: Sucrose.Inference) => Sucrose.Inference;