@exobase/core v1.0.0-rc.31
title: 'core' description: 'The core Exobase library package'
group: 'Packages'
Provides the core types and functions to implement the Abstract & Compose design pattern with the Exobase library.
If you're writing endpoints (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 hooks you'll want the core package for the response parsing functions.
Install
yarn add @exobase/coreUsage
If you're writing 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)
}Response Parsing
An endpoint function can return any object as the result. If the result is an AnbstractResponse object it should be parsed and applied with all specified headers, body, and status. If the result is any other object it should be treated as the json body and returned as such in the response.
The core package gives you a few small helpers to deal with these results that are not always known. A function can throw an error, return an Response object, or return any other object. In almost any case, all of these need to be converted to an Response so they can be applied to a framework.
For an example, see the source for the useExpress hook.
import { props, responseFromError, responseFromResult } from '@exobase/core'propsis a helper you can use in a root hook to generate the initialPropsobject. Think of it like a constructor.responseFromErrorwill convert an error object into anResponse, handling error objects and unkonwn errors.responseFromResultwill convert a function's result into anResponse, handling both cases mentioned above.
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago