@loro-dev/flock 3.0.0 → 4.0.0

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/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ type ExportOptions = {
4
4
  from?: VersionVector;
5
5
  hooks?: ExportHooks;
6
6
  pruneTombstonesBefore?: number;
7
+ peerId?: string;
7
8
  };
8
9
  type ImportOptions = {
9
10
  bundle: ExportBundle;
@@ -13,7 +14,11 @@ type VersionVectorEntry = {
13
14
  physicalTime: number;
14
15
  logicalCounter: number;
15
16
  };
16
- type VersionVector = Record<string, VersionVectorEntry>;
17
+ interface VersionVector {
18
+ [peer: string]: VersionVectorEntry | undefined;
19
+ }
20
+ declare function encodeVersionVector(vector: VersionVector): Uint8Array;
21
+ declare function decodeVersionVector(bytes: Uint8Array): VersionVector;
17
22
  type Value = string | number | boolean | null | Array<Value> | {
18
23
  [key: string]: Value;
19
24
  };
@@ -33,6 +38,11 @@ type EntryClock = {
33
38
  logicalCounter: number;
34
39
  peerId: string;
35
40
  };
41
+ type EntryInfo = {
42
+ data?: Value;
43
+ metadata: MetadataMap;
44
+ clock: EntryClock;
45
+ };
36
46
  type ExportPayload = {
37
47
  data?: Value;
38
48
  metadata?: MetadataMap;
@@ -134,6 +144,14 @@ declare class Flock {
134
144
  */
135
145
  delete(key: KeyPart[], now?: number): void;
136
146
  get(key: KeyPart[]): Value | undefined;
147
+ /**
148
+ * Returns the full entry payload (data, metadata, and clock) for a key.
149
+ *
150
+ * Unlike `get`, this distinguishes between a missing key (`undefined`) and a
151
+ * tombstone (returns the clock and metadata with `data` omitted). Metadata is
152
+ * cloned and defaults to `{}` when absent.
153
+ */
154
+ getEntry(key: KeyPart[]): EntryInfo | undefined;
137
155
  merge(other: Flock): void;
138
156
  version(): VersionVector;
139
157
  private exportJsonInternal;
@@ -146,6 +164,7 @@ declare class Flock {
146
164
  private importJsonWithHooks;
147
165
  importJson(bundle: ExportBundle): ImportReport;
148
166
  importJson(options: ImportOptions): Promise<ImportReport>;
167
+ importJsonStr(bundle: string): ImportReport;
149
168
  getMaxPhysicalTime(): number;
150
169
  peerId(): string;
151
170
  digest(): string;
@@ -156,5 +175,5 @@ declare class Flock {
156
175
  subscribe(listener: (batch: EventBatch) => void): () => void;
157
176
  }
158
177
  //#endregion
159
- export { EntryClock, Event, EventBatch, EventPayload, ExportBundle, ExportHookContext, ExportHooks, ExportPayload, ExportRecord, Flock, ImportAccept, ImportDecision, ImportHookContext, ImportHooks, ImportPayload, ImportReport, ImportSkip, KeyPart, MetadataMap, PutHookContext, PutHooks, PutPayload, PutWithMetaOptions, ScanBound, ScanOptions, ScanRow, Value, VersionVector, VersionVectorEntry };
178
+ export { EntryClock, EntryInfo, Event, EventBatch, EventPayload, ExportBundle, ExportHookContext, ExportHooks, ExportPayload, ExportRecord, Flock, ImportAccept, ImportDecision, ImportHookContext, ImportHooks, ImportPayload, ImportReport, ImportSkip, KeyPart, MetadataMap, PutHookContext, PutHooks, PutPayload, PutWithMetaOptions, ScanBound, ScanOptions, ScanRow, Value, VersionVector, VersionVectorEntry, decodeVersionVector, encodeVersionVector };
160
179
  //# sourceMappingURL=index.d.mts.map
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ type ExportOptions = {
4
4
  from?: VersionVector;
5
5
  hooks?: ExportHooks;
6
6
  pruneTombstonesBefore?: number;
7
+ peerId?: string;
7
8
  };
8
9
  type ImportOptions = {
9
10
  bundle: ExportBundle;
@@ -13,7 +14,11 @@ type VersionVectorEntry = {
13
14
  physicalTime: number;
14
15
  logicalCounter: number;
15
16
  };
16
- type VersionVector = Record<string, VersionVectorEntry>;
17
+ interface VersionVector {
18
+ [peer: string]: VersionVectorEntry | undefined;
19
+ }
20
+ declare function encodeVersionVector(vector: VersionVector): Uint8Array;
21
+ declare function decodeVersionVector(bytes: Uint8Array): VersionVector;
17
22
  type Value = string | number | boolean | null | Array<Value> | {
18
23
  [key: string]: Value;
19
24
  };
@@ -33,6 +38,11 @@ type EntryClock = {
33
38
  logicalCounter: number;
34
39
  peerId: string;
35
40
  };
41
+ type EntryInfo = {
42
+ data?: Value;
43
+ metadata: MetadataMap;
44
+ clock: EntryClock;
45
+ };
36
46
  type ExportPayload = {
37
47
  data?: Value;
38
48
  metadata?: MetadataMap;
@@ -134,6 +144,14 @@ declare class Flock {
134
144
  */
135
145
  delete(key: KeyPart[], now?: number): void;
136
146
  get(key: KeyPart[]): Value | undefined;
147
+ /**
148
+ * Returns the full entry payload (data, metadata, and clock) for a key.
149
+ *
150
+ * Unlike `get`, this distinguishes between a missing key (`undefined`) and a
151
+ * tombstone (returns the clock and metadata with `data` omitted). Metadata is
152
+ * cloned and defaults to `{}` when absent.
153
+ */
154
+ getEntry(key: KeyPart[]): EntryInfo | undefined;
137
155
  merge(other: Flock): void;
138
156
  version(): VersionVector;
139
157
  private exportJsonInternal;
@@ -146,6 +164,7 @@ declare class Flock {
146
164
  private importJsonWithHooks;
147
165
  importJson(bundle: ExportBundle): ImportReport;
148
166
  importJson(options: ImportOptions): Promise<ImportReport>;
167
+ importJsonStr(bundle: string): ImportReport;
149
168
  getMaxPhysicalTime(): number;
150
169
  peerId(): string;
151
170
  digest(): string;
@@ -156,5 +175,5 @@ declare class Flock {
156
175
  subscribe(listener: (batch: EventBatch) => void): () => void;
157
176
  }
158
177
  //#endregion
159
- export { EntryClock, Event, EventBatch, EventPayload, ExportBundle, ExportHookContext, ExportHooks, ExportPayload, ExportRecord, Flock, ImportAccept, ImportDecision, ImportHookContext, ImportHooks, ImportPayload, ImportReport, ImportSkip, KeyPart, MetadataMap, PutHookContext, PutHooks, PutPayload, PutWithMetaOptions, ScanBound, ScanOptions, ScanRow, Value, VersionVector, VersionVectorEntry };
178
+ export { EntryClock, EntryInfo, Event, EventBatch, EventPayload, ExportBundle, ExportHookContext, ExportHooks, ExportPayload, ExportRecord, Flock, ImportAccept, ImportDecision, ImportHookContext, ImportHooks, ImportPayload, ImportReport, ImportSkip, KeyPart, MetadataMap, PutHookContext, PutHooks, PutPayload, PutWithMetaOptions, ScanBound, ScanOptions, ScanRow, Value, VersionVector, VersionVectorEntry, decodeVersionVector, encodeVersionVector };
160
179
  //# sourceMappingURL=index.d.ts.map