Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@automerge/automerge-repo

Package Overview
Dependencies
Maintainers
4
Versions
69
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 1.0.0-alpha.4 to 1.0.0-alpha.5

test/helpers/generate-large-object.ts

4

dist/DocHandle.js

@@ -80,3 +80,3 @@ import * as A from "@automerge/automerge/next";

NETWORK_READY: { target: REQUESTING },
}
},
},

@@ -345,2 +345,2 @@ requesting: {

export const { IDLE, LOADING, AWAITING_NETWORK, REQUESTING, READY, FAILED, DELETED, UNAVAILABLE, } = HandleState;
const { CREATE, FIND, REQUEST, UPDATE, TIMEOUT, DELETE, REQUEST_COMPLETE, MARK_UNAVAILABLE, AWAIT_NETWORK, NETWORK_READY } = Event;
const { CREATE, FIND, REQUEST, UPDATE, TIMEOUT, DELETE, REQUEST_COMPLETE, MARK_UNAVAILABLE, AWAIT_NETWORK, NETWORK_READY, } = Event;

@@ -6,6 +6,5 @@ import { EventEmitter } from "eventemitter3";

peerId?: PeerId;
abstract connect(url?: string): void;
abstract connect(peerId: PeerId): void;
abstract send(message: Message): void;
abstract join(): void;
abstract leave(): void;
abstract disconnect(): void;
}

@@ -12,0 +11,0 @@ export interface NetworkAdapterEvents {

@@ -11,4 +11,2 @@ import { EventEmitter } from "eventemitter3";

send(message: MessageContents): void;
join(): void;
leave(): void;
isReady: () => boolean;

@@ -21,3 +19,3 @@ whenReady: () => Promise<void>;

message: (payload: Message) => void;
"ready": () => void;
ready: () => void;
}

@@ -24,0 +22,0 @@ export interface PeerPayload {

@@ -69,3 +69,2 @@ import { EventEmitter } from "eventemitter3";

networkAdapter.connect(this.peerId);
networkAdapter.join();
}

@@ -97,10 +96,2 @@ send(message) {

}
join() {
this.#log(`Joining network`);
this.#adapters.forEach(a => a.join());
}
leave() {
this.#log(`Leaving network`);
this.#adapters.forEach(a => a.leave());
}
isReady = () => {

@@ -107,0 +98,0 @@ return this.#readyAdapterCount === this.#adapters.length;

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

#log = debug(`automerge-repo:storage-subsystem`);
#snapshotting = false;
constructor(storageAdapter) {

@@ -47,2 +48,3 @@ this.#storageAdapter = storageAdapter;

async #saveTotal(documentId, doc, sourceChunks) {
this.#snapshotting = true;
const binary = A.save(doc);

@@ -61,2 +63,3 @@ const snapshotHash = headsHash(A.getHeads(doc));

this.#chunkInfos.set(documentId, newChunkInfos);
this.#snapshotting = false;
}

@@ -102,3 +105,3 @@ async loadDoc(documentId) {

async remove(documentId) {
this.#storageAdapter.remove([documentId, "snapshot"]);
this.#storageAdapter.removeRange([documentId, "snapshot"]);
this.#storageAdapter.removeRange([documentId, "incremental"]);

@@ -118,2 +121,5 @@ }

#shouldCompact(sourceChunks) {
if (this.#snapshotting) {
return false;
}
// compact if the incremental size is greater than the snapshot size

@@ -130,3 +136,3 @@ let snapshotSize = 0;

}
return incrementalSize > snapshotSize;
return incrementalSize >= snapshotSize;
}

@@ -133,0 +139,0 @@ }

{
"name": "@automerge/automerge-repo",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "A repository object to manage a collection of automerge documents",

@@ -34,3 +34,3 @@ "repository": "https://github.com/automerge/automerge-repo",

"peerDependencies": {
"@automerge/automerge": "^2.1.0-alpha.12"
"@automerge/automerge": "^2.1.0-alpha.13"
},

@@ -69,3 +69,3 @@ "dependencies": {

},
"gitHead": "fbf71f0c3aaa2786a4e279f336f01d665f53ce5b"
"gitHead": "9cd9be160ebda37c8f0d70f2d5cadea5b951a3c3"
}

@@ -104,3 +104,3 @@ import * as A from "@automerge/automerge/next"

NETWORK_READY: { target: REQUESTING },
}
},
},

@@ -505,3 +505,3 @@ requesting: {

| MarkUnavailableEvent
| AwaitNetworkEvent
| AwaitNetworkEvent
| NetworkReadyEvent

@@ -546,3 +546,3 @@

AWAIT_NETWORK,
NETWORK_READY
NETWORK_READY,
} = Event

@@ -8,9 +8,7 @@ import { EventEmitter } from "eventemitter3"

abstract connect(url?: string): void
abstract connect(peerId: PeerId): void
abstract send(message: Message): void
abstract join(): void
abstract leave(): void
abstract disconnect(): void
}

@@ -17,0 +15,0 @@

@@ -28,9 +28,6 @@ import { EventEmitter } from "eventemitter3"

#ephemeralSessionCounts: Record<EphemeralMessageSource, number> = {}
#readyAdapterCount = 0
#readyAdapterCount = 0
#adapters: NetworkAdapter[] = []
constructor(
adapters: NetworkAdapter[],
public peerId = randomPeerId()
) {
constructor(adapters: NetworkAdapter[], public peerId = randomPeerId()) {
super()

@@ -45,3 +42,8 @@ this.#log = debug(`automerge-repo:network:${this.peerId}`)

this.#readyAdapterCount++
this.#log("Adapters ready: ", this.#readyAdapterCount, "/", this.#adapters.length)
this.#log(
"Adapters ready: ",
this.#readyAdapterCount,
"/",
this.#adapters.length
)
if (this.#readyAdapterCount === this.#adapters.length) {

@@ -105,3 +107,2 @@ this.emit("ready")

networkAdapter.connect(this.peerId)
networkAdapter.join()
}

@@ -122,7 +123,7 @@

: {
...message,
count: ++this.#count,
sessionId: this.#sessionId,
senderId: this.peerId,
}
...message,
count: ++this.#count,
sessionId: this.#sessionId,
senderId: this.peerId,
}
this.#log("Ephemeral message", outbound)

@@ -137,12 +138,2 @@ peer.send(outbound)

join() {
this.#log(`Joining network`)
this.#adapters.forEach(a => a.join())
}
leave() {
this.#log(`Leaving network`)
this.#adapters.forEach(a => a.leave())
}
isReady = () => {

@@ -175,3 +166,3 @@ return this.#readyAdapterCount === this.#adapters.length

message: (payload: Message) => void
"ready": () => void
ready: () => void
}

@@ -178,0 +169,0 @@

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

#snapshotting = false
constructor(storageAdapter: StorageAdapter) {

@@ -71,2 +73,3 @@ this.#storageAdapter = storageAdapter

): Promise<void> {
this.#snapshotting = true
const binary = A.save(doc)

@@ -91,2 +94,3 @@ const snapshotHash = headsHash(A.getHeads(doc))

this.#chunkInfos.set(documentId, newChunkInfos)
this.#snapshotting = false
}

@@ -134,3 +138,3 @@

async remove(documentId: DocumentId) {
this.#storageAdapter.remove([documentId, "snapshot"])
this.#storageAdapter.removeRange([documentId, "snapshot"])
this.#storageAdapter.removeRange([documentId, "incremental"])

@@ -154,2 +158,5 @@ }

#shouldCompact(sourceChunks: StorageChunkInfo[]) {
if (this.#snapshotting) {
return false
}
// compact if the incremental size is greater than the snapshot size

@@ -165,3 +172,3 @@ let snapshotSize = 0

}
return incrementalSize > snapshotSize
return incrementalSize >= snapshotSize
}

@@ -168,0 +175,0 @@ }

@@ -9,3 +9,3 @@ import { NetworkAdapter } from "../../src/index.js"

}
send() {}
send() { }
connect(_: string) {

@@ -16,4 +16,3 @@ if (this.#startReady) {

}
join() {}
leave() {}
disconnect() { }
}

@@ -21,2 +21,6 @@ import assert from "assert"

import { READY, AWAITING_NETWORK } from "../src/DocHandle.js"
import {
generateLargeObject,
LargeObject,
} from "./helpers/generate-large-object.js"

@@ -102,3 +106,2 @@ describe("Repo", () => {

await eventPromise(handle, "unavailable")
})

@@ -135,3 +138,2 @@

assert.equal(bobHandle.isReady(), true)
})

@@ -168,2 +170,3 @@

})
// we now have a snapshot and an incremental change in storage
assert.equal(handle.isReady(), true)

@@ -281,2 +284,17 @@ await handle.doc()

})
it("doesn't create multiple snapshots in storage when a series of large changes are made in succession", async () => {
const { repo, storageAdapter } = setup()
const handle = repo.create<{ objects: LargeObject[] }>()
for (let i = 0; i < 5; i++) {
handle.change(d => {
d.objects = []
d.objects.push(generateLargeObject(100))
})
}
const storageKeyTypes = storageAdapter.keys().map(k => k.split(".")[1])
assert(storageKeyTypes.filter(k => k === "snapshot").length === 1)
})
})

@@ -339,3 +357,5 @@

function doConnectAlice() {
aliceRepo.networkSubsystem.addNetworkAdapter(new MessageChannelNetworkAdapter(aliceToBob))
aliceRepo.networkSubsystem.addNetworkAdapter(
new MessageChannelNetworkAdapter(aliceToBob)
)
//bobRepo.networkSubsystem.addNetworkAdapter(new MessageChannelNetworkAdapter(bobToAlice))

@@ -589,5 +609,5 @@ }

? // heads, create a new doc
repo.create<TestDoc>()
repo.create<TestDoc>()
: // tails, pick a random doc
(getRandomItem(docs) as DocHandle<TestDoc>)
(getRandomItem(docs) as DocHandle<TestDoc>)

@@ -594,0 +614,0 @@ // make sure the doc is ready

Sorry, the diff of this file is not supported yet

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