Eventually you will be able to npm install but until then...
Either by npm install'ing the git repo, cloning it, or downloading a
release.
Replicache JS SDK is written in TypeScript. Run npm run build to generate the JS source code (JS source is outputted in out/). By default we generate browser compatible JS but you can also build CommonJS modules by running npm run build:cjs. Let us know what your needs are.
Download required helper binaries: npm run build:binaries. Do this again whenever you update the SDK.
Currently, the JavaScript SDK relies on a native local server that implements the guts of the sync protocol on the client side. This is temporary and will be removed.
For now, you must have this server running whenever you are working with the SDK:
mkdir ~/.repm
npm run start:test-server -- --storage-dir=$HOME/.repm
See Replicache Server Setup for server-side instructions.
For the rest of these instructions we will assume your data layer is
running on localhost:3000.
In production, your app will talk to the production Replicache diff-server at https://serve.replicache.dev/.
During development, that sever can't reach your workstation, so we provide a development instance to work against instead. Leave this running in a tab:
# The --client-view flag should point to the Client View endpoint
# on your development data layer.
npm run start:diff-server -- --client-view="http://localhost:3000/replicache-client-view"By default we only compile the TS to an ES module.
import Replicache, {REPMHTTPInvoker} from './out/mod.js';To use Replicache you currently have to tell it how to invoke the Replicache Client API Module (REPM).
const diffServerURL = 'https://serve.replicache.dev/pull';
const diffServerAuth = '<your diff-server account ID>';
const batchURL = 'https://youservice.com/replicache-batch';
const dataLayerAuth = '<your data-layer auth token>';
const repmInvoker = new REPMHTTPInvoker('http://localhost:7002');
const repmInvoke = repmInvoker.invoke;
const replicache = new Replicache({
diffServerURL,
diffServerAuth,
batchURL,
dataLayerAuth,
repmInvoke,
});
await replicache.query(async tx => {
console.log(await tx.get('/hello'));
});