https://github.com/eyedea-io/syncano
Custom wrapper for syncano-core library
https://github.com/eyedea-io/syncano
syncano
Last synced: about 1 year ago
JSON representation
Custom wrapper for syncano-core library
- Host: GitHub
- URL: https://github.com/eyedea-io/syncano
- Owner: eyedea-io
- License: mit
- Created: 2018-04-17T04:31:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T20:26:27.000Z (over 3 years ago)
- Last Synced: 2025-03-15T19:01:44.799Z (over 1 year ago)
- Topics: syncano
- Language: TypeScript
- Size: 1.09 MB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @eyedea/syncano
Custom wrapper for @syncano/core library.
[](https://npmjs.com/package/@eyedea/syncano)
[](https://github.com/eyedea-io/syncano/blob/master/LICENSE)
## Install
```
$ npm install --save @eyedea/syncano
```
## Usage
```ts
import * as S from '@eyedea/syncano'
// Define arguments that endpoint will receive
interface Args {
id: string
}
class Endpoint extends S.Endpoint {
async run(
{data, response /* users, endpoint etc. */}: S.Core, // Access to syncano
{args, meta, config}: S.Context // Access to args, meta and config
) {
if (!this.user) {
// Errors thrown using S.HttpError are returned as response. In this case:
// {message: 'Unauthorized!'} with status code 401
throw new S.HttpError('Unauthorized!', 401)
}
// You can directly return syncano query ...
return data.post.find(10)
// ... or use response method
response.json({posts}, 200)
}
// Any error thrown in `run` method can be handled using `endpointDidCatch` method
endpointDidCatch({message}: Error) {
this.syncano.response.json({message}, 400)
}
}
export default async (ctx: S.Context) => S.init(MyEndpoint, ctx)
```
## Tests
View [@eyedea/syncano-test](https://github.com/eyedea-io/syncano-test)
## License
MIT © Eyedea AS