@automerge/automerge-repo 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/DocHandle.js +1 -1
- package/dist/Repo.js +1 -1
- package/dist/helpers/headsAreSame.d.ts +1 -0
- package/dist/helpers/headsAreSame.d.ts.map +1 -1
- package/dist/network/NetworkAdapter.d.ts +3 -1
- package/dist/network/NetworkAdapter.d.ts.map +1 -1
- package/dist/network/NetworkAdapter.js +3 -1
- package/dist/network/NetworkAdapterInterface.d.ts +4 -0
- package/dist/network/NetworkAdapterInterface.d.ts.map +1 -1
- package/dist/synchronizer/DocSynchronizer.d.ts +1 -1
- package/dist/synchronizer/DocSynchronizer.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/DocHandle.ts +1 -1
- package/src/Repo.ts +1 -1
- package/src/network/NetworkAdapter.ts +3 -1
- package/src/network/NetworkAdapterInterface.ts +6 -1
- package/src/synchronizer/DocSynchronizer.ts +1 -1
- package/test/helpers/DummyStorageAdapter.ts +2 -2
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ A `Repo` exposes these methods:
|
|
|
52
52
|
- `.on("document", ({handle: DocHandle}) => void)`
|
|
53
53
|
Registers a callback to be fired each time a new document is loaded or created.
|
|
54
54
|
- `.on("delete-document", ({handle: DocHandle}) => void)`
|
|
55
|
-
Registers a callback to be fired each time a new document is
|
|
55
|
+
Registers a callback to be fired each time a new document is deleted.
|
|
56
56
|
|
|
57
57
|
A `DocHandle` is a wrapper around an `Automerge.Doc`. Its primary function is to dispatch changes to
|
|
58
58
|
the document.
|
package/dist/DocHandle.js
CHANGED
package/dist/Repo.js
CHANGED
|
@@ -156,7 +156,7 @@ export class Repo extends EventEmitter {
|
|
|
156
156
|
const heads = handle.getRemoteHeads(storageId);
|
|
157
157
|
const haveHeadsChanged = message.syncState.theirHeads &&
|
|
158
158
|
(!heads || !headsAreSame(heads, message.syncState.theirHeads));
|
|
159
|
-
if (haveHeadsChanged) {
|
|
159
|
+
if (haveHeadsChanged && message.syncState.theirHeads) {
|
|
160
160
|
handle.setRemoteHeads(storageId, message.syncState.theirHeads);
|
|
161
161
|
if (storageId && this.#remoteHeadsGossipingEnabled) {
|
|
162
162
|
this.#remoteHeadsSubscriptions.handleImmediateRemoteHeadsChanged(message.documentId, storageId, message.syncState.theirHeads);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headsAreSame.d.ts","sourceRoot":"","sources":["../../src/helpers/headsAreSame.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"headsAreSame.d.ts","sourceRoot":"","sources":["../../src/helpers/headsAreSame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAGjD,eAAO,MAAM,YAAY,iCAExB,CAAA"}
|
|
@@ -4,12 +4,14 @@ import { PeerId } from "../types.js";
|
|
|
4
4
|
import { Message } from "./messages.js";
|
|
5
5
|
import { NetworkAdapterInterface } from "./NetworkAdapterInterface.js";
|
|
6
6
|
/** An interface representing some way to connect to other peers
|
|
7
|
-
* @deprecated use {@link NetworkAdapterInterface}
|
|
8
7
|
*
|
|
9
8
|
* @remarks
|
|
10
9
|
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
11
10
|
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
12
11
|
* until the adapter emits a `ready` event before it starts trying to use it
|
|
12
|
+
*
|
|
13
|
+
* This utility class can be used as a base to build a custom network adapter. It
|
|
14
|
+
* is most useful as a simple way to add the necessary event emitter functionality
|
|
13
15
|
*/
|
|
14
16
|
export declare abstract class NetworkAdapter extends EventEmitter<NetworkAdapterEvents> implements NetworkAdapterInterface {
|
|
15
17
|
peerId?: PeerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkAdapter.d.ts","sourceRoot":"","sources":["../../src/network/NetworkAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAEtE
|
|
1
|
+
{"version":3,"file":"NetworkAdapter.d.ts","sourceRoot":"","sources":["../../src/network/NetworkAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAEtE;;;;;;;;;GASG;AACH,8BAAsB,cACpB,SAAQ,YAAY,CAAC,oBAAoB,CACzC,YAAW,uBAAuB;IAElC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI;IAEnE;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAErC,gEAAgE;IAChE,QAAQ,CAAC,UAAU,IAAI,IAAI;CAC5B"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/* c8 ignore start */
|
|
2
2
|
import { EventEmitter } from "eventemitter3";
|
|
3
3
|
/** An interface representing some way to connect to other peers
|
|
4
|
-
* @deprecated use {@link NetworkAdapterInterface}
|
|
5
4
|
*
|
|
6
5
|
* @remarks
|
|
7
6
|
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
8
7
|
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
9
8
|
* until the adapter emits a `ready` event before it starts trying to use it
|
|
9
|
+
*
|
|
10
|
+
* This utility class can be used as a base to build a custom network adapter. It
|
|
11
|
+
* is most useful as a simple way to add the necessary event emitter functionality
|
|
10
12
|
*/
|
|
11
13
|
export class NetworkAdapter extends EventEmitter {
|
|
12
14
|
peerId;
|
|
@@ -18,6 +18,10 @@ export interface PeerMetadata {
|
|
|
18
18
|
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
19
19
|
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
20
20
|
* until the adapter emits a `ready` event before it starts trying to use it
|
|
21
|
+
*
|
|
22
|
+
* The {@link NetworkAdapter} is an abstract class that can be used as a base to build a
|
|
23
|
+
* custom network adapter. It is most useful as a simple way to add the necessary event
|
|
24
|
+
* emitter functionality
|
|
21
25
|
*/
|
|
22
26
|
export interface NetworkAdapterInterface extends EventEmitter<NetworkAdapterEvents> {
|
|
23
27
|
peerId?: PeerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkAdapterInterface.d.ts","sourceRoot":"","sources":["../../src/network/NetworkAdapterInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"NetworkAdapterInterface.d.ts","sourceRoot":"","sources":["../../src/network/NetworkAdapterInterface.ts"],"names":[],"mappings":"AAE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;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -6,7 +6,7 @@ import { Synchronizer } from "./Synchronizer.js";
|
|
|
6
6
|
type PeerDocumentStatus = "unknown" | "has" | "unavailable" | "wants";
|
|
7
7
|
interface DocSynchronizerConfig {
|
|
8
8
|
handle: DocHandle<unknown>;
|
|
9
|
-
onLoadSyncState?: (peerId: PeerId) => A.SyncState | undefined
|
|
9
|
+
onLoadSyncState?: (peerId: PeerId) => Promise<A.SyncState | undefined>;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* DocSynchronizer takes a handle to an Automerge document, and receives & dispatches sync messages
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocSynchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/DocSynchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,2BAA2B,CAAA;AAG9C,OAAO,EACL,SAAS,EAKV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,gBAAgB,EAEhB,WAAW,EACX,cAAc,EACd,WAAW,EAEZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,KAAK,kBAAkB,GAAG,SAAS,GAAG,KAAK,GAAG,aAAa,GAAG,OAAO,CAAA;AAOrE,UAAU,qBAAqB;IAC7B,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC1B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"DocSynchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/DocSynchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,2BAA2B,CAAA;AAG9C,OAAO,EACL,SAAS,EAKV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,gBAAgB,EAEhB,WAAW,EACX,cAAc,EACd,WAAW,EAEZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,KAAK,kBAAkB,GAAG,SAAS,GAAG,KAAK,GAAG,aAAa,GAAG,OAAO,CAAA;AAOrE,UAAU,qBAAqB;IAC7B,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC1B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAA;CACvE;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,YAAY;;IAE/C,gBAAgB,SAAM;gBAsBV,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,qBAAqB;IAyB9D,IAAI,UAAU,uCAEb;IAED,IAAI,UAAU,qCAEb;IAkID,OAAO,CAAC,MAAM,EAAE,MAAM;IAItB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE;IAmD3B,OAAO,CAAC,MAAM,EAAE,MAAM;IAKtB,cAAc,CAAC,OAAO,EAAE,WAAW;IAkBnC,uBAAuB,CAAC,OAAO,EAAE,gBAAgB;IAuBjD,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc;CA8EzD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automerge/automerge-repo",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "A repository object to manage a collection of automerge documents",
|
|
5
5
|
"repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo",
|
|
6
6
|
"author": "Peter van Hardenberg <pvh@pvh.ca>",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "e819a7ed6302ce34f372b119ea3e8bab052e3af6"
|
|
59
59
|
}
|
package/src/DocHandle.ts
CHANGED
|
@@ -383,7 +383,7 @@ export class DocHandle<T> //
|
|
|
383
383
|
payload: {
|
|
384
384
|
callback: (doc: A.Doc<T>) => {
|
|
385
385
|
const result = A.changeAt(doc, heads, options, callback)
|
|
386
|
-
resultHeads = result.newHeads
|
|
386
|
+
resultHeads = result.newHeads || undefined
|
|
387
387
|
return result.newDoc
|
|
388
388
|
},
|
|
389
389
|
},
|
package/src/Repo.ts
CHANGED
|
@@ -214,7 +214,7 @@ export class Repo extends EventEmitter<RepoEvents> {
|
|
|
214
214
|
message.syncState.theirHeads &&
|
|
215
215
|
(!heads || !headsAreSame(heads, message.syncState.theirHeads))
|
|
216
216
|
|
|
217
|
-
if (haveHeadsChanged) {
|
|
217
|
+
if (haveHeadsChanged && message.syncState.theirHeads) {
|
|
218
218
|
handle.setRemoteHeads(storageId, message.syncState.theirHeads)
|
|
219
219
|
|
|
220
220
|
if (storageId && this.#remoteHeadsGossipingEnabled) {
|
|
@@ -7,12 +7,14 @@ import { Message } from "./messages.js"
|
|
|
7
7
|
import { NetworkAdapterInterface } from "./NetworkAdapterInterface.js"
|
|
8
8
|
|
|
9
9
|
/** An interface representing some way to connect to other peers
|
|
10
|
-
* @deprecated use {@link NetworkAdapterInterface}
|
|
11
10
|
*
|
|
12
11
|
* @remarks
|
|
13
12
|
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
14
13
|
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
15
14
|
* until the adapter emits a `ready` event before it starts trying to use it
|
|
15
|
+
*
|
|
16
|
+
* This utility class can be used as a base to build a custom network adapter. It
|
|
17
|
+
* is most useful as a simple way to add the necessary event emitter functionality
|
|
16
18
|
*/
|
|
17
19
|
export abstract class NetworkAdapter
|
|
18
20
|
extends EventEmitter<NetworkAdapterEvents>
|
|
@@ -22,8 +22,13 @@ export interface PeerMetadata {
|
|
|
22
22
|
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
23
23
|
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
24
24
|
* until the adapter emits a `ready` event before it starts trying to use it
|
|
25
|
+
*
|
|
26
|
+
* The {@link NetworkAdapter} is an abstract class that can be used as a base to build a
|
|
27
|
+
* custom network adapter. It is most useful as a simple way to add the necessary event
|
|
28
|
+
* emitter functionality
|
|
25
29
|
*/
|
|
26
|
-
export interface NetworkAdapterInterface
|
|
30
|
+
export interface NetworkAdapterInterface
|
|
31
|
+
extends EventEmitter<NetworkAdapterEvents> {
|
|
27
32
|
peerId?: PeerId
|
|
28
33
|
peerMetadata?: PeerMetadata
|
|
29
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Chunk,
|
|
1
|
+
import { Chunk, StorageAdapterInterface, type StorageKey } from "../../src/index.js"
|
|
2
2
|
|
|
3
|
-
export class DummyStorageAdapter implements
|
|
3
|
+
export class DummyStorageAdapter implements StorageAdapterInterface {
|
|
4
4
|
#data: Record<string, Uint8Array> = {}
|
|
5
5
|
|
|
6
6
|
#keyToString(key: string[]): string {
|