Exports
createEndpointFactory
The main export from CEF, used to create an endpoint factory.
Utilities
ResError
The Error
subclass used by CEF to indicate an error has an associated HTTP code that should be used.
You can extend this to create custom errors that can be used in a custom error serialisation function, with the ability to have associated HTTP codes.
miniSerializeError
The default error serialisation function used for uncaught errors, from Redux Toolkit. See RTK Docs for more details on how it works.
nothing
A unique value that a handler should return to indicate that it has completed, and CEF shouldn't conduct its usual response handling.
decorateHandler
A utility for decorating NextJS handlers.
decorateHandler(handler, withFoo, withBar);
Types
SerializedError
The return from miniSerializeError
. See RTK Docs for more details.
Parser
Describes a function which takes an input and returns a value, possibly of a new type.
type MyParser = Parser<{ foo: true }, object, [secondParam: string]>;
is equivalent to
type MyParser = (input: object, secondParam: string) => { foo: true };
FailWithCode
Describes the failWithCode
function passed to relevant CEF callbacks.
This accepts the same parameters as ResError
's constructor - it just doesn't need the new
keyword.
GenericsFromHandler
A utility type for extracting types from an endpoint's handler.
type Generics = GenericsFromHandler<typeof endpoint.handler>;
const result = (await res.json()) as Generics['return'];
Decorator
Describes a decorator. Can specify a custom return type which will be reflected in final handler.
const withFoo: Decorator<{ foo: true }> = (handler) => (req, res) => {
if (req.body.foo) {
return res.status(200).json({ foo: true });
}
return handler(req, res);
};
To avoid pollution of the type, decorators which use a return type of any
will not be reflected in the final return type.