New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@automerge/automerge-repo

Package Overview
Dependencies
Maintainers
0
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automerge/automerge-repo - npm Package Compare versions

Comparing version 2.0.0-alpha.22 to 2.0.0-alpha.23

9

dist/DocHandle.d.ts

@@ -68,11 +68,2 @@ import * as A from "@automerge/automerge/slim/next";

/**
* @returns the current state of this handle's Automerge document.
*
* This is the recommended way to access a handle's document. Note that this waits for the handle
* to be ready if necessary. If loading (or synchronization) fails, this will never resolve.
*/
legacyAsyncDoc(
/** states to wait for, such as "LOADING". mostly for internal use. */
awaitStates?: HandleState[]): Promise<A.Doc<T> | undefined>;
/**
* Returns the current state of the Automerge document this handle manages.

@@ -79,0 +70,0 @@ *

22

dist/DocHandle.js

@@ -232,22 +232,2 @@ import * as A from "@automerge/automerge/slim/next";

/**
* @returns the current state of this handle's Automerge document.
*
* This is the recommended way to access a handle's document. Note that this waits for the handle
* to be ready if necessary. If loading (or synchronization) fails, this will never resolve.
*/
async legacyAsyncDoc(
/** states to wait for, such as "LOADING". mostly for internal use. */
awaitStates = ["ready", "unavailable"]) {
try {
// wait for the document to enter one of the desired states
await this.#statePromise(awaitStates);
}
catch (error) {
// if we timed out, return undefined
return undefined;
}
// Return the document
return !this.isUnavailable() ? this.#doc : undefined;
}
/**
* Returns the current state of the Automerge document this handle manages.

@@ -537,3 +517,3 @@ *

handle: this,
data: encode(message),
data: new Uint8Array(encode(message)),
});

@@ -540,0 +520,0 @@ }

54

dist/synchronizer/DocSynchronizer.js

@@ -40,3 +40,2 @@ import * as A from "@automerge/automerge/slim/next";

void (async () => {
await handle.whenReady([READY, REQUESTING]);
this.#processAllPendingSyncMessages();

@@ -53,6 +52,10 @@ })();

async #syncWithPeers() {
const doc = await this.#handle.legacyAsyncDoc(); // XXX THIS ONE IS WEIRD
if (doc === undefined)
return;
this.#peers.forEach(peerId => this.#sendSyncMessage(peerId, doc));
try {
await this.#handle.whenReady();
const doc = this.#handle.doc(); // XXX THIS ONE IS WEIRD
this.#peers.forEach(peerId => this.#sendSyncMessage(peerId, doc));
}
catch (e) {
console.log("sync with peers threw an exception");
}
}

@@ -160,18 +163,12 @@ async #broadcastToPeers({ data, }) {

async beginSync(peerIds) {
const noPeersWithDocument = peerIds.every(peerId => this.#peerDocumentStatuses[peerId] in ["unavailable", "wants"]);
// At this point if we don't have anything in our storage, we need to use an empty doc to sync
// with; but we don't want to surface that state to the front end
const docPromise = this.#handle // TODO THIS IS ALSO WEIRD
.legacyAsyncDoc([READY, REQUESTING, UNAVAILABLE])
.then(doc => {
// we register out peers first, then say that sync has started
void this.#handle
.whenReady([READY, REQUESTING, UNAVAILABLE])
.then(() => {
this.#syncStarted = true;
this.#checkDocUnavailable();
const wasUnavailable = doc === undefined;
if (wasUnavailable && noPeersWithDocument) {
return;
}
// If the doc is unavailable we still need a blank document to generate
// the sync message from
return doc ?? A.init();
})
.catch(e => {
console.log("caught whenready", e);
this.#syncStarted = true;
this.#checkDocUnavailable();
});

@@ -192,7 +189,18 @@ const peersWithDocument = this.#peers.some(peerId => {

this.#setSyncState(peerId, reparsedSyncState);
docPromise
.then(doc => {
if (doc) {
this.#sendSyncMessage(peerId, doc);
// At this point if we don't have anything in our storage, we need to use an empty doc to sync
// with; but we don't want to surface that state to the front end
this.#handle
.whenReady([READY, REQUESTING, UNAVAILABLE])
.then(() => {
const doc = this.#handle.isReady()
? this.#handle.doc()
: A.init();
const noPeersWithDocument = peerIds.every(peerId => this.#peerDocumentStatuses[peerId] in ["unavailable", "wants"]);
const wasUnavailable = doc === undefined;
if (wasUnavailable && noPeersWithDocument) {
return;
}
// If the doc is unavailable we still need a blank document to generate
// the sync message from
this.#sendSyncMessage(peerId, doc ?? A.init());
})

@@ -199,0 +207,0 @@ .catch(err => {

{
"name": "@automerge/automerge-repo",
"version": "2.0.0-alpha.22",
"version": "2.0.0-alpha.23",
"description": "A repository object to manage a collection of automerge documents",

@@ -23,2 +23,3 @@ "repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo",

"http-server": "^14.1.0",
"ts-node": "^10.9.2",
"vite": "^5.0.8"

@@ -33,4 +34,2 @@ },

"fast-sha256": "^1.3.0",
"tiny-typed-emitter": "^2.1.0",
"ts-node": "^10.9.1",
"uuid": "^9.0.0",

@@ -65,3 +64,3 @@ "xstate": "^5.9.1"

},
"gitHead": "b30af9827bed4615ba3c5e9ee93ca483915e4016"
"gitHead": "82a9bed7cc6a92940f3aa68167f6990123dda58e"
}

@@ -235,3 +235,3 @@ # Automerge Repo

// main.tsx
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket" // <-- add this line
import { WebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket" // <-- add this line

@@ -243,3 +243,3 @@ // ...

new BroadcastChannelNetworkAdapter(),
new BrowserWebSocketClientAdapter("ws://localhost:3030"), // <-- add this line
new WebSocketClientAdapter("ws://localhost:3030"), // <-- add this line
],

@@ -266,1 +266,2 @@ storage: new IndexedDBStorageAdapter(),

- Dylan Mackenzie
- Maciek Sakrejda

@@ -279,23 +279,2 @@ import * as A from "@automerge/automerge/slim/next"

/**
* @returns the current state of this handle's Automerge document.
*
* This is the recommended way to access a handle's document. Note that this waits for the handle
* to be ready if necessary. If loading (or synchronization) fails, this will never resolve.
*/
async legacyAsyncDoc(
/** states to wait for, such as "LOADING". mostly for internal use. */
awaitStates: HandleState[] = ["ready", "unavailable"]
) {
try {
// wait for the document to enter one of the desired states
await this.#statePromise(awaitStates)
} catch (error) {
// if we timed out, return undefined
return undefined
}
// Return the document
return !this.isUnavailable() ? this.#doc : undefined
}
/**
* Returns the current state of the Automerge document this handle manages.

@@ -639,3 +618,3 @@ *

handle: this,
data: encode(message),
data: new Uint8Array(encode(message)),
})

@@ -642,0 +621,0 @@ }

@@ -89,3 +89,2 @@ import * as A from "@automerge/automerge/slim/next"

void (async () => {
await handle.whenReady([READY, REQUESTING])
this.#processAllPendingSyncMessages()

@@ -106,5 +105,9 @@ })()

async #syncWithPeers() {
const doc = await this.#handle.legacyAsyncDoc() // XXX THIS ONE IS WEIRD
if (doc === undefined) return
this.#peers.forEach(peerId => this.#sendSyncMessage(peerId, doc))
try {
await this.#handle.whenReady()
const doc = this.#handle.doc() // XXX THIS ONE IS WEIRD
this.#peers.forEach(peerId => this.#sendSyncMessage(peerId, doc))
} catch (e) {
console.log("sync with peers threw an exception")
}
}

@@ -236,24 +239,13 @@

async beginSync(peerIds: PeerId[]) {
const noPeersWithDocument = peerIds.every(
peerId => this.#peerDocumentStatuses[peerId] in ["unavailable", "wants"]
)
// At this point if we don't have anything in our storage, we need to use an empty doc to sync
// with; but we don't want to surface that state to the front end
const docPromise = this.#handle // TODO THIS IS ALSO WEIRD
.legacyAsyncDoc([READY, REQUESTING, UNAVAILABLE])
.then(doc => {
// we register out peers first, then say that sync has started
void this.#handle
.whenReady([READY, REQUESTING, UNAVAILABLE])
.then(() => {
this.#syncStarted = true
this.#checkDocUnavailable()
const wasUnavailable = doc === undefined
if (wasUnavailable && noPeersWithDocument) {
return
}
// If the doc is unavailable we still need a blank document to generate
// the sync message from
return doc ?? A.init<unknown>()
})
.catch(e => {
console.log("caught whenready", e)
this.#syncStarted = true
this.#checkDocUnavailable()
})

@@ -279,7 +271,24 @@ const peersWithDocument = this.#peers.some(peerId => {

docPromise
.then(doc => {
if (doc) {
this.#sendSyncMessage(peerId, doc)
// At this point if we don't have anything in our storage, we need to use an empty doc to sync
// with; but we don't want to surface that state to the front end
this.#handle
.whenReady([READY, REQUESTING, UNAVAILABLE])
.then(() => {
const doc = this.#handle.isReady()
? this.#handle.doc()
: A.init<unknown>()
const noPeersWithDocument = peerIds.every(
peerId =>
this.#peerDocumentStatuses[peerId] in ["unavailable", "wants"]
)
const wasUnavailable = doc === undefined
if (wasUnavailable && noPeersWithDocument) {
return
}
// If the doc is unavailable we still need a blank document to generate
// the sync message from
this.#sendSyncMessage(peerId, doc ?? A.init<unknown>())
})

@@ -286,0 +295,0 @@ .catch(err => {

@@ -262,4 +262,2 @@ import * as A from "@automerge/automerge/next"

handle.legacyAsyncDoc()
assert(vi.getTimerCount() > timerCount)

@@ -266,0 +264,0 @@

@@ -258,3 +258,2 @@ import { next as A } from "@automerge/automerge"

const bobHandle = await repo2.find<TestDoc>(handle.url)
await bobHandle.whenReady()
assert.deepEqual(bobHandle.doc(), { foo: "saved" })

@@ -310,3 +309,2 @@ })

assert.equal(handle.isReady(), true)
await handle.whenReady()

@@ -1068,7 +1066,2 @@ await pause()

// make sure the doc is ready
if (!doc.isReady()) {
await doc.whenReady()
}
// make a random change to it

@@ -1246,3 +1239,2 @@ doc.change(d => {

const charlieHandle = await charlieRepo.find<TestDoc>(handle.url)
await charlieHandle.whenReady()

@@ -1249,0 +1241,0 @@ // make a change on charlie

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc