Skip to content

Commit

Permalink
ClientSettings -> SharedSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
sgwilym committed Dec 13, 2022
1 parent 0d466e5 commit 8632074
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ changes are like.

## Other

- Added a new `ClientSettings` class for easily saving and retrieving an author
- Added a new `SharedSettings` class for easily saving and retrieving an author
keypair, shares and secrets, and favourite servers.
- Added parseAuthorOrShareAddress
- Added a new minified web bundle, available from CDN_LINK_HERE
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ to persist between runs:
- An author to using for signing documents
- Servers to sync with

Earthstar offers a `ClientSettings` API which persists settings for these
Earthstar offers a `SharedSettings` API which persists settings for these
between sessions in all runtimes supporting the WebStorage APIs:

```ts
const settings = new ClientSettings();
const settings = new SharedSettings();
settings.author = authorKeypair;
settings.addShare(myShareAddress);
Expand All @@ -439,7 +439,7 @@ It also offers a method which instantiates a new `Peer` with replicas for all
shares already added:

```ts
const settings = new ClientSettings();
const settings = new SharedSettings();
// Create a peer with all saved shares and sync once with all saved servers.
const peer = settings.getPeer({
Expand Down
77 changes: 77 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/entries/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export * from "../util/doc-types.ts";
export * from "../util/errors.ts";
export * from "../util/log.ts";
export * from "../util/misc.ts";
export * from "../util/client_settings.ts";
export * from "../util/shared_settings.ts";
6 changes: 3 additions & 3 deletions src/test/misc/client_settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { AuthorKeypair, ShareKeypair } from "../../crypto/crypto-types.ts";
import { Crypto } from "../../crypto/crypto.ts";
import { ClientSettings } from "../../util/client_settings.ts";
import { SharedSettings } from "../../util/client_settings.ts";
import { isErr, notErr } from "../../util/errors.ts";
import { assert, assertEquals } from "../asserts.ts";
import { isNode } from "https://deno.land/x/which_runtime@0.2.0/mod.ts";
import { Replica } from "../../replica/replica.ts";
import { ReplicaDriverMemory } from "../../replica/driver_memory.ts";

Deno.test({
name: "ClientSettings",
name: "SharedSettings",
// Don't run this on Node where it'll implode.
ignore: isNode,
fn: async (test) => {
const settings = new ClientSettings();
const settings = new SharedSettings();

const shareAKeypair = await Crypto.generateShareKeypair(
"apples",
Expand Down
8 changes: 4 additions & 4 deletions src/util/client_settings.ts → src/util/shared_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SHARES_KEY = "shares";
const SHARE_SECRETS_KEY = "share_secrets";
const SERVERS_KEY = "servers";

type ClientSettingsOpts = {
type SharedSettingsOpts = {
/** A namespace to restrict these settings to. */
namespace?: string;
/** Whether to use session storage for these settings. */
Expand All @@ -24,11 +24,11 @@ type ClientSettingsOpts = {
*
* Uses the Storage API, so only clients on the same origin will share the same settings.
*/
export class ClientSettings {
export class SharedSettings {
private namespace: string | undefined;
private storage = localStorage;

constructor(opts?: ClientSettingsOpts) {
constructor(opts?: SharedSettingsOpts) {
this.namespace = opts?.namespace;

if (opts?.sessionOnly) {
Expand Down Expand Up @@ -335,7 +335,7 @@ export class ClientSettings {
): {
/** A preconfigured Peer. */
peer: Peer;
/** Stop changes to ClientSettings from propagating to the Peer. */
/** Stop changes to SharedSettings from propagating to the Peer. */
unsubscribeFromSettings: () => void;
} {
const peer = new Peer();
Expand Down

0 comments on commit 8632074

Please sign in to comment.