tokra v0.0.1-rc.3
@exobase/core
Provides the core types and functions to implement the Abstract & Compose design pattern
If you're writing Exobase endpoint (following the Abstract & Compose design pattern) and you're using Typescript you'll probably want this package for the types. If you're developing your own Exobase hooks you'll want the core package for the response parsing functions.
Install
yarn add @exobase/core
Usage
If you're writing Exobase endpoints in Typescript you'll want to import the Props
type.
import { compose } from 'radash'
import type { Props } from '@exobase/core'
const endpoint = (props: Props) => {
console.log(props)
}
export default compose()
// ...
If you're writing your own hooks you'll want to use a bit more.
Response Parsing
An Exobase endpoint function can return any object and it should be returned as the json body. If an Exobase endpoint returns a Response
object it should be parsed and applied with all specified headers, body, and status.
The core package gives you a few small helpers to determine the shape of a returned object so you know how to handle it.
For an example, see the source for the useExpress
hook.
import { initProps, responseFromError, responseFromResult } from '@exobase/core'
initProps
is a helper you can use in a root hook to generate the initialProps
objectresponseFromError
will convert an error object into an ExobaseResponse
, handling Exobase error objects and unkonwn errors.responseFromResult
will convert a function's result into an ExobaseResponse
, handling both cases mentioned above.