UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

90 lines (88 loc) 3.09 kB
import { ErrorResult, LucidErrorData, ResponseBody, ServiceContext, ServiceFn, ServiceResponse, ServiceWrapperConfig } from "./types-CfF1T11a.js"; import z, { ZodType } from "zod/v4"; import { Context } from "hono"; import * as hono_openapi43 from "hono-openapi"; import { OpenAPIV3 } from "openapi-types"; //#region src/utils/errors/lucid-api-error.d.ts /** * The LucidAPIError class should be used to throw errors within the API request lifecycle. This will be caught by Hono's error handler and will return a formatted error response. If the error is a Zod error, it will be formatted into a more readable format. * @class * @extends Error * @param {LucidErrorData} error * @returns {void} * @example * throw new LucidAPIError({ * type: "basic", * name: "Fetch User Error", * message: "Error while fetching user data", * status: 500, * }); * @example * throw new LucidAPIError({ * type: "validation", * name: "Validation Error", * message: "Validation error occurred", * status: 400, * errors: { * body: { * email: { * code: "invalid_email", * message: "Invalid email address", * }, * }, * }, * }); */ declare class LucidAPIError extends Error { error: LucidErrorData; constructor(error: LucidErrorData); static formatZodErrors(error: z.core.$ZodIssue[]): ErrorResult; } //#endregion //#region src/libs/http/utils/build-response.d.ts interface BuildResponseParams { data: unknown; pagination?: { count: number; page: number; perPage: number; }; } type FormatAPIResponse = (c: Context, params: BuildResponseParams) => ResponseBody; declare const formatAPIResponse: FormatAPIResponse; //#endregion //#region src/utils/services/service-wrapper.d.ts declare const serviceWrapper: <T extends unknown[], R>(fn: ServiceFn<T, R>, wrapperConfig: ServiceWrapperConfig) => (service: ServiceContext, ...args: T) => ServiceResponse<R>; //#endregion //#region src/utils/swagger/hono-swagger-response.d.ts /** * Used to construct a response object for Swagger */ declare const honoSwaggerResponse: (config?: { schema?: unknown; paginated?: boolean; noProperties?: boolean; }) => Record<string, OpenAPIV3.ResponseObject | OpenAPIV3.ReferenceObject>; //#endregion //#region src/utils/swagger/hono-swagger-request-body.d.ts declare const honoSwaggerRequestBody: (schema: ZodType) => OpenAPIV3.RequestBodyObject; //#endregion //#region src/utils/swagger/hono-swagger-paramaters.d.ts /** * Used to construct paramaters JSON schema for Swagger */ declare const honoSwaggerParamaters: (props: { headers?: { csrf?: boolean; contentLocale?: boolean; clientKey?: boolean; authorization?: boolean; }; params?: ZodType; query?: ZodType; }) => (OpenAPIV3.ParameterObject | (OpenAPIV3.ParameterObject & { schema: hono_openapi43.ResolverResult; }))[]; //#endregion export { LucidAPIError, formatAPIResponse, honoSwaggerParamaters, honoSwaggerRequestBody, honoSwaggerResponse, serviceWrapper }; //# sourceMappingURL=api.d.ts.map