@outsidecube/db-api-sync
v0.3.0
Published
Local/remote synchronization library targeted to offline first apps
Downloads
8
Readme
Getting started
Installation
Install this library
npm install --save @outsidecube/db-api-sync
Configuration
In order to configure this you will need to provide.
1. Processor object
Before you start using the Synchronizer, you will need to write a class that implements HTTPResponseProcessor
, with the following signature:
readEntities(callback: EntityFetchCallback, originalRequest: HTTPRequest): Promise<void>
This would be a minimal example:
import {
EntityDef,
EntityFetchCallback,
HTTPRequest,
HTTPResponseProcessor,
} from '@outsidecube/db-api-sync';
export default class MyCustomProcessor implements HTTPResponseProcessor {
async readEntities(
callback: EntityFetchCallback,
entityDef: EntityDef,
originalRequest: HTTPRequest,
): Promise<void> {
const r: Response = await originalRequest.fetch();
const { data } = await r.json();
for (const element of data) {
await callback(entityDef, element);
}
}
}
2. Configuration Object
The configuration object has a structure defined in SynchronizerConfig.ts
. It has the following elements:
{
baseURI: "[base URI for API]",
fetchers: [
{
name: "default",
default: true,
type: "RESTEntityFetcher",
config: {
//here comes the custom procesor defined
"responseProcessor": new MyCustomProcessor();
}
}
]
}
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. The starting point for contributing is understanding the class design:
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2023 Outside The Cube. This project is BSD licensed.