Skip to content

Commit

Permalink
Merge pull request #311 from earthstar-project/readme-node-updates
Browse files Browse the repository at this point in the history
Update README with details on namespacing for NPM distribution.
  • Loading branch information
sgwilym authored Feb 13, 2023
2 parents f76a67a + 7720399 commit b336669
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ It can be imported via URL into a browser:
Or Deno:

```ts
import * as Earthstar from "https://deno.land/x/earthstar/mod.ts";`}
import * as Earthstar from "https://deno.land/x/earthstar/mod.ts";
```

> Earthstar's web syncing does not work with version of Deno between 1.27.0 -
Expand All @@ -52,6 +52,15 @@ or installed with NPM:
{`npm install earthstar`}
```

```ts
import * as Earthstar from "earthstar";

// Node and browser APIs are namespaced in the NPM distribution:
import { ReplicaDriverWeb } from "earthstar/browser";
import { ReplicaDriverSqlite } from "earthstar/node";

```

We recommend the browser and Deno versions. This module has been built with many
standard web APIs that have need to be polyfilled to work in Node.

Expand Down
2 changes: 1 addition & 1 deletion README_SERVERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Server } from "https://deno.land/x/earthstar/mod.ts";
For NPM:

```
npm install @earthstar-project/server
npm install earthstar
```

```ts
Expand Down
5 changes: 5 additions & 0 deletions src/entries/browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Earthstar APIs which run in browsers.
* @module
*/

export { DocDriverLocalStorage } from "../replica/doc_drivers/localstorage.ts";
export { DocDriverIndexedDB } from "../replica/doc_drivers/indexeddb.ts";
export { AttachmentDriverIndexedDB } from "../replica/attachment_drivers/indexeddb.ts";
Expand Down
5 changes: 5 additions & 0 deletions src/entries/deno.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Earthstar APIs which run in the Deno runtime.
* @module
*/

export { ReplicaDriverFs } from "../replica/driver_fs.ts";
export { DocDriverLocalStorage } from "../replica/doc_drivers/localstorage.ts";
export { DocDriverSqlite } from "../replica/doc_drivers/sqlite.deno.ts";
Expand Down
5 changes: 5 additions & 0 deletions src/entries/node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Earthstar APIs which run in the Node runtime.
* @module
*/

export { CryptoDriverChloride } from "../crypto/crypto-driver-chloride.ts";
export { CryptoDriverNode } from "../crypto/crypto-driver-node.js";
export { DocDriverSqlite } from "../replica/doc_drivers/sqlite.node.ts";
Expand Down
57 changes: 57 additions & 0 deletions src/entries/universal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
/**
* [Earthstar](https://earthstar-project.org) is a small and resilient distributed storage protocol designed with a strong focus on simplicity and versatility, with the social realities of peer-to-peer computing kept in mind.
*
* This is a reference implementation written in Typescript. You can use it to add Earthstar functionality to applications running on servers, browsers, the command line, or anywhere else JavaScript can be run.
*
* ### Example usage
*
* ```ts
* import { Replica, ReplicaDriverMemory, Crypto, Peer } from "earthstar";
*
* const shareKeypair = await Crypto.generateShareKeypair("gardening");
*
* const replica = new Replica({
* driver: ReplicaDriverMemory(shareKeypair.shareAddress),
* shareSecret: shareKeypair.secret,
* });
*
* const authorKeypair = await Crypto.generateAuthorKeypair("suzy");
*
* await replica.set(authorKeypair, {
* path: "/my-note",
* text: "Saw seven magpies today",
* });
*
* const allDocs = await replica.getAllDocs();
*
* const peer = new Peer();
*
* peer.addReplica(replica);
*
* peer.sync("https://my.server")
* ```
*
* This module also exposes server APIs for for building always-online peers. The below example reads some on-disk JSON to initiate some share replicas, and stores their data using the filesystem.
*
* ```ts
* import {
* ExtensionKnownShares,
* ExtensionSyncWeb,
* Server,
* } from "https://deno.land/x/earthstar/mod.ts";
*
* const server = new Server([
* new ExtensionKnownShares({
* knownSharesPath: "./known_shares.json",
* onCreateReplica: (shareAddress) => {
* return new Earthstar.Replica({
* driver: new ReplicaDriverFs(shareAddress, "./share_data"),
* });
* },
* }),
* new ExtensionSyncWebsocket(),
* ]);
*
* @module
*/

export * from "../core-validators/addresses.ts";
export * from "../core-validators/characters.ts";
export * from "../core-validators/checkers.ts";
Expand Down

0 comments on commit b336669

Please sign in to comment.