@dabble/patches 0.8.15 → 0.8.17

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.
@@ -237,4 +237,4 @@ declare abstract class BaseDoc<T extends object = object> extends ReadonlyStoreC
237
237
  abstract import(snapshot: PatchesSnapshot<T>): void;
238
238
  }
239
239
 
240
- export { BaseDoc as B, OTDoc as O, type PatchesDocOptions as P, type PatchesDoc as a };
240
+ export { BaseDoc as B, OTDoc as O, type PatchesDoc as P, type PatchesDocOptions as a };
@@ -1,5 +1,5 @@
1
1
  import { OTStoreBackend } from '../../../server/types.js';
2
- import { EditableVersionMetadata, VersionMetadata, Change } from '../../../types.js';
2
+ import { EditableVersionMetadata, Change, VersionMetadata } from '../../../types.js';
3
3
  import '../../../json-patch/types.js';
4
4
  import '../../../json-patch/JSONPatch.js';
5
5
  import '@dabble/delta';
@@ -1,6 +1,6 @@
1
1
  import 'easy-signal';
2
2
  import '../json-patch/types.js';
3
3
  import '../types.js';
4
- export { B as BaseDoc } from '../BaseDoc-CD5wZQMm.js';
4
+ export { B as BaseDoc } from '../BaseDoc-BT18xPxU.js';
5
5
  import '../json-patch/JSONPatch.js';
6
6
  import '@dabble/delta';
@@ -1,6 +1,6 @@
1
1
  import { JSONPatchOp } from '../json-patch/types.js';
2
2
  import { PatchesSnapshot, Change } from '../types.js';
3
- import { a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
3
+ import { P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
4
4
  import { PatchesStore, TrackedDoc } from './PatchesStore.js';
5
5
  import '../json-patch/JSONPatch.js';
6
6
  import '@dabble/delta';
@@ -196,6 +196,7 @@ class IndexedDBStore {
196
196
  if (existing.deleted) {
197
197
  await docsStore.put({
198
198
  ...existing,
199
+ committedRev: 0,
199
200
  deleted: void 0,
200
201
  ...algorithm && { algorithm }
201
202
  });
@@ -2,7 +2,7 @@ import { JSONPatchOp } from '../json-patch/types.js';
2
2
  import { PatchesSnapshot, Change } from '../types.js';
3
3
  import { ClientAlgorithm } from './ClientAlgorithm.js';
4
4
  import { LWWClientStore } from './LWWClientStore.js';
5
- import { a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
5
+ import { P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
6
6
  import { TrackedDoc } from './PatchesStore.js';
7
7
  import '../json-patch/JSONPatch.js';
8
8
  import '@dabble/delta';
@@ -1,5 +1,5 @@
1
1
  import { PatchesSnapshot, Change } from '../types.js';
2
- import { B as BaseDoc } from '../BaseDoc-CD5wZQMm.js';
2
+ import { B as BaseDoc } from '../BaseDoc-BT18xPxU.js';
3
3
  import '../json-patch/JSONPatch.js';
4
4
  import '@dabble/delta';
5
5
  import '../json-patch/types.js';
@@ -2,7 +2,7 @@ import { JSONPatchOp } from '../json-patch/types.js';
2
2
  import { PatchesSnapshot, Change } from '../types.js';
3
3
  import { ClientAlgorithm } from './ClientAlgorithm.js';
4
4
  import { OTClientStore } from './OTClientStore.js';
5
- import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
5
+ import { a as PatchesDocOptions, P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
6
6
  import { TrackedDoc } from './PatchesStore.js';
7
7
  import '../json-patch/JSONPatch.js';
8
8
  import '@dabble/delta';
@@ -1,5 +1,5 @@
1
1
  import '../types.js';
2
- export { O as OTDoc } from '../BaseDoc-CD5wZQMm.js';
2
+ export { O as OTDoc } from '../BaseDoc-BT18xPxU.js';
3
3
  import '../json-patch/JSONPatch.js';
4
4
  import '@dabble/delta';
5
5
  import '../json-patch/types.js';
@@ -3,7 +3,7 @@ import { Unsubscriber } from 'easy-signal';
3
3
  import { JSONPatchOp } from '../json-patch/types.js';
4
4
  import { Change } from '../types.js';
5
5
  import { ClientAlgorithm } from './ClientAlgorithm.js';
6
- import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
6
+ import { a as PatchesDocOptions, P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
7
7
  import { AlgorithmName } from './PatchesStore.js';
8
8
  import '../json-patch/JSONPatch.js';
9
9
  import '@dabble/delta';
@@ -1,5 +1,4 @@
1
1
  import { Store } from 'easy-signal';
2
- import { SizeCalculator } from '../algorithms/ot/shared/changeBatching.js';
3
2
  import { BranchAPI } from '../net/protocol/types.js';
4
3
  import { Branch, ListBranchesOptions, CreateBranchMetadata, EditableBranchMetadata } from '../types.js';
5
4
  import { BranchClientStore } from './BranchClientStore.js';
@@ -9,13 +8,9 @@ import '../json-patch/JSONPatch.js';
9
8
  import '@dabble/delta';
10
9
  import '../json-patch/types.js';
11
10
  import './ClientAlgorithm.js';
12
- import '../BaseDoc-CD5wZQMm.js';
11
+ import '../BaseDoc-BT18xPxU.js';
13
12
 
14
13
  interface PatchesBranchClientOptions {
15
- /** Maximum size in bytes for a single change in storage. Used to break large initial changes. */
16
- maxStorageBytes?: number;
17
- /** Custom size calculator for change size measurement. */
18
- sizeCalculator?: SizeCalculator;
19
14
  /** Algorithm to use for the branch document (defaults to the Patches instance default). */
20
15
  algorithm?: AlgorithmName;
21
16
  }
@@ -122,8 +122,9 @@ class PatchesBranchClient {
122
122
  committedAt: 0
123
123
  });
124
124
  let initChanges = [rootReplace];
125
- if (this.options?.maxStorageBytes) {
126
- initChanges = breakChanges(initChanges, this.options.maxStorageBytes, this.options.sizeCalculator);
125
+ const options = this.patches.docOptions;
126
+ if (options.maxStorageBytes) {
127
+ initChanges = breakChanges(initChanges, options.maxStorageBytes, options.sizeCalculator);
127
128
  }
128
129
  const contentStartRev = initChanges[initChanges.length - 1].rev + 1;
129
130
  const algorithmName = this.options?.algorithm ?? this.patches.defaultAlgorithm;
@@ -1,6 +1,6 @@
1
1
  import 'easy-signal';
2
2
  import '../json-patch/types.js';
3
3
  import '../types.js';
4
- export { O as OTDoc, a as PatchesDoc, P as PatchesDocOptions } from '../BaseDoc-CD5wZQMm.js';
4
+ export { O as OTDoc, P as PatchesDoc, a as PatchesDocOptions } from '../BaseDoc-BT18xPxU.js';
5
5
  import '../json-patch/JSONPatch.js';
6
6
  import '@dabble/delta';
@@ -1,6 +1,6 @@
1
1
  import { AlgorithmName } from './PatchesStore.js';
2
2
  import { Patches } from './Patches.js';
3
- import { P as PatchesDocOptions } from '../BaseDoc-CD5wZQMm.js';
3
+ import { a as PatchesDocOptions } from '../BaseDoc-BT18xPxU.js';
4
4
  import '../types.js';
5
5
  import '../json-patch/JSONPatch.js';
6
6
  import '@dabble/delta';
@@ -1,4 +1,4 @@
1
- export { B as BaseDoc, O as OTDoc, a as PatchesDoc, P as PatchesDocOptions } from '../BaseDoc-CD5wZQMm.js';
1
+ export { B as BaseDoc, O as OTDoc, P as PatchesDoc, a as PatchesDocOptions } from '../BaseDoc-BT18xPxU.js';
2
2
  export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmExternalDBPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches, upgradePatchesDB } from './factories.js';
3
3
  export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './IndexedDBStore.js';
4
4
  export { OTIndexedDBStore } from './OTIndexedDBStore.js';
@@ -23,5 +23,4 @@ import '../types.js';
23
23
  import '../json-patch/JSONPatch.js';
24
24
  import '@dabble/delta';
25
25
  import '../utils/deferred.js';
26
- import '../algorithms/ot/shared/changeBatching.js';
27
26
  import '../net/protocol/types.js';
@@ -1,20 +1,3 @@
1
- /**
2
- * Generate a fractional index which is a sortable string(s) between a and b. Use an empty string or null/undefined to
3
- * represent the start and end of the range.
4
- *
5
- * Pass a count to generate N fractional indexes between a and b.
6
- *
7
- * See https://www.figma.com/blog/realtime-editing-of-ordered-sequences/#fractional-indexing and
8
- * https://observablehq.com/@dgreensp/implementing-fractional-indexing for more information.
9
- */
10
- declare function fractionalIndex(a: string | undefined | null, b: string | undefined | null): string;
11
- declare function fractionalIndex(a: string | undefined | null, b: string | undefined | null, count: number): string[];
12
- declare namespace fractionalIndex {
13
- var sort: typeof sortByOrder;
14
- var heal: typeof healDuplicateOrders;
15
- }
16
- /** Order field parameter type: field name, or false when values are order strings directly */
17
- type OrderFieldParam = string | false;
18
1
  /**
19
2
  * Sort a map of items by their fractional index order, with key as tiebreaker.
20
3
  *
@@ -32,7 +15,8 @@ type OrderFieldParam = string | false;
32
15
  * const sorted = sortByOrder({ b: 'a2', a: 'a1' }, false);
33
16
  * // [['a', 'a1'], ['b', 'a2']]
34
17
  */
35
- declare function sortByOrder<T extends Record<string, unknown> | string>(items: Record<string, T>, orderField?: OrderFieldParam): Array<[string, T]>;
18
+ declare function sortByOrder<T extends Record<O, string>, O extends string = 'order'>(items: Record<string, T>, orderField?: O): Array<[string, T]>;
19
+ declare function sortByOrder(items: Record<string, string>, orderField: false): Array<[string, string]>;
36
20
  /**
37
21
  * Detect duplicate `order` values and return fixes. Duplicates can occur when multiple
38
22
  * clients generate the same fractional index while offline (e.g., both appending to a list).
@@ -62,6 +46,22 @@ declare function sortByOrder<T extends Record<string, unknown> | string>(items:
62
46
  * // Values are the order strings directly
63
47
  * const fixes = healDuplicateOrders({ a: 'a1', b: 'a1' }, false);
64
48
  */
65
- declare function healDuplicateOrders<T extends Record<string, unknown> | string>(items: Record<string, T>, orderField?: OrderFieldParam): Record<string, string> | null;
49
+ declare function healDuplicateOrders<T extends Record<O, string>, O extends string = 'order'>(items: Record<string, T>, orderField?: O): Record<string, string> | null;
50
+ declare function healDuplicateOrders(items: Record<string, string>, orderField: false): Record<string, string> | null;
51
+ /**
52
+ * Generate a fractional index which is a sortable string(s) between a and b. Use an empty string or null/undefined to
53
+ * represent the start and end of the range.
54
+ *
55
+ * Pass a count to generate N fractional indexes between a and b.
56
+ *
57
+ * See https://www.figma.com/blog/realtime-editing-of-ordered-sequences/#fractional-indexing and
58
+ * https://observablehq.com/@dgreensp/implementing-fractional-indexing for more information.
59
+ */
60
+ declare function fractionalIndex(a: string | undefined | null, b: string | undefined | null): string;
61
+ declare function fractionalIndex(a: string | undefined | null, b: string | undefined | null, count: number): string[];
62
+ declare namespace fractionalIndex {
63
+ var sort: typeof sortByOrder;
64
+ var heal: typeof healDuplicateOrders;
65
+ }
66
66
 
67
67
  export { fractionalIndex, healDuplicateOrders, sortByOrder };
@@ -4,8 +4,6 @@ const INTEGER_ZERO = "a0";
4
4
  const SMALLEST_INTEGER = "A00000000000000000000000000";
5
5
  const LARGEST_INTEGER = "zzzzzzzzzzzzzzzzzzzzzzzzzzz";
6
6
  const ZERO = digits[0];
7
- fractionalIndex.sort = sortByOrder;
8
- fractionalIndex.heal = healDuplicateOrders;
9
7
  function fractionalIndex(a, b, count) {
10
8
  if (count !== void 0) {
11
9
  if (count === 0) {
@@ -200,6 +198,9 @@ function createOrderGetter(orderField) {
200
198
  return orderField === false ? (value) => value : (value) => value[orderField];
201
199
  }
202
200
  function sortByOrder(items, orderField = "order") {
201
+ return sortByOrderImpl(items, orderField);
202
+ }
203
+ function sortByOrderImpl(items, orderField) {
203
204
  const getOrder = createOrderGetter(orderField);
204
205
  return Object.entries(items).sort((a, b) => {
205
206
  const orderA = getOrder(a[1]);
@@ -212,7 +213,7 @@ function sortByOrder(items, orderField = "order") {
212
213
  function healDuplicateOrders(items, orderField = "order") {
213
214
  const getOrder = createOrderGetter(orderField);
214
215
  const fixes = {};
215
- const entries = sortByOrder(items, orderField);
216
+ const entries = sortByOrderImpl(items, orderField);
216
217
  if (entries.length < 2) return null;
217
218
  let prevOrder = getOrder(entries[0][1]);
218
219
  for (let i = 1; i < entries.length; i++) {
@@ -236,6 +237,7 @@ function healDuplicateOrders(items, orderField = "order") {
236
237
  }
237
238
  return Object.keys(fixes).length > 0 ? fixes : null;
238
239
  }
240
+ Object.assign(fractionalIndex, { sort: sortByOrder, heal: healDuplicateOrders });
239
241
  export {
240
242
  fractionalIndex,
241
243
  healDuplicateOrders,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Delta } from '@dabble/delta';
2
- export { B as BaseDoc, O as OTDoc, a as PatchesDoc, P as PatchesDocOptions } from './BaseDoc-CD5wZQMm.js';
2
+ export { B as BaseDoc, O as OTDoc, P as PatchesDoc, a as PatchesDocOptions } from './BaseDoc-BT18xPxU.js';
3
3
  export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmExternalDBPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches, upgradePatchesDB } from './client/factories.js';
4
4
  export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './client/IndexedDBStore.js';
5
5
  export { OTIndexedDBStore } from './client/OTIndexedDBStore.js';
@@ -33,7 +33,6 @@ export { JSONPatch, PathLike, WriteOptions } from './json-patch/JSONPatch.js';
33
33
  export { ApplyJSONPatchOptions, JSONPatchOp, JSONPatchOpHandlerMap } from './json-patch/types.js';
34
34
  export { Branch, Change, ChangeInput, ChangeMutator, CommitChangesOptions, CreateBranchMetadata, DeleteDocOptions, DocSyncState, DocSyncStatus, DocumentTombstone, EditableBranchMetadata, EditableVersionMetadata, ListBranchesOptions, ListChangesOptions, ListVersionsOptions, PatchesSnapshot, PatchesState, PathProxy, VersionMetadata } from './types.js';
35
35
  import './utils/deferred.js';
36
- import './algorithms/ot/shared/changeBatching.js';
37
36
  import './net/protocol/types.js';
38
37
  import './json-patch/ops/add.js';
39
38
  import './json-patch/ops/copy.js';
@@ -13,7 +13,7 @@ import { WebSocketOptions } from './websocket/WebSocketTransport.js';
13
13
  import '../json-patch/JSONPatch.js';
14
14
  import '@dabble/delta';
15
15
  import '../json-patch/types.js';
16
- import '../BaseDoc-CD5wZQMm.js';
16
+ import '../BaseDoc-BT18xPxU.js';
17
17
  import '../utils/deferred.js';
18
18
 
19
19
  interface PatchesSyncState {
@@ -22,7 +22,7 @@ import '../algorithms/ot/shared/changeBatching.js';
22
22
  import '../client/BranchClientStore.js';
23
23
  import '../client/ClientAlgorithm.js';
24
24
  import '../json-patch/types.js';
25
- import '../BaseDoc-CD5wZQMm.js';
25
+ import '../BaseDoc-BT18xPxU.js';
26
26
  import '../client/PatchesStore.js';
27
27
  import '../client/Patches.js';
28
28
  import '../server/types.js';
@@ -1,5 +1,5 @@
1
1
  import { ApiDefinition } from '../net/protocol/JSONRPCServer.js';
2
- import { EditableBranchMetadata, CreateBranchMetadata, Branch } from '../types.js';
2
+ import { EditableBranchMetadata, Branch, CreateBranchMetadata } from '../types.js';
3
3
  import 'easy-signal';
4
4
  import '../net/websocket/AuthorizationProvider.js';
5
5
  import './types.js';
@@ -1,5 +1,5 @@
1
1
  import { Patches, OpenDocOptions } from '../client/Patches.js';
2
- import { a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
2
+ import { P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
3
3
  import 'easy-signal';
4
4
  import '../json-patch/types.js';
5
5
  import '../types.js';
@@ -7,7 +7,7 @@ import '../types.js';
7
7
  import '../json-patch/JSONPatch.js';
8
8
  import '@dabble/delta';
9
9
  import '../client/ClientAlgorithm.js';
10
- import '../BaseDoc-CD5wZQMm.js';
10
+ import '../BaseDoc-BT18xPxU.js';
11
11
  import '../client/PatchesStore.js';
12
12
  import '../algorithms/ot/shared/changeBatching.js';
13
13
  import '../client/BranchClientStore.js';
@@ -6,5 +6,5 @@ import '../types.js';
6
6
  import '../json-patch/JSONPatch.js';
7
7
  import '@dabble/delta';
8
8
  import '../client/ClientAlgorithm.js';
9
- import '../BaseDoc-CD5wZQMm.js';
9
+ import '../BaseDoc-BT18xPxU.js';
10
10
  import '../client/PatchesStore.js';
@@ -11,7 +11,7 @@ import '../types.js';
11
11
  import '../json-patch/JSONPatch.js';
12
12
  import '@dabble/delta';
13
13
  import '../client/ClientAlgorithm.js';
14
- import '../BaseDoc-CD5wZQMm.js';
14
+ import '../BaseDoc-BT18xPxU.js';
15
15
  import '../client/PatchesStore.js';
16
16
  import '../net/PatchesSync.js';
17
17
  import '../algorithms/ot/shared/changeBatching.js';
@@ -1,6 +1,6 @@
1
1
  import { Accessor } from 'solid-js';
2
2
  import { OpenDocOptions } from '../client/Patches.js';
3
- import { a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
3
+ import { P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
4
4
  import { ChangeMutator } from '../types.js';
5
5
  import 'easy-signal';
6
6
  import '../json-patch/types.js';
@@ -1,6 +1,6 @@
1
- import { ShallowRef, Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
1
+ import { ShallowRef, Ref, MaybeRef, MaybeRefOrGetter } from 'vue';
2
2
  import { OpenDocOptions } from '../client/Patches.js';
3
- import { a as PatchesDoc } from '../BaseDoc-CD5wZQMm.js';
3
+ import { P as PatchesDoc } from '../BaseDoc-BT18xPxU.js';
4
4
  import { ChangeMutator } from '../types.js';
5
5
  import 'easy-signal';
6
6
  import '../json-patch/types.js';
@@ -6,5 +6,5 @@ import '../types.js';
6
6
  import '../json-patch/JSONPatch.js';
7
7
  import '@dabble/delta';
8
8
  import '../client/ClientAlgorithm.js';
9
- import '../BaseDoc-CD5wZQMm.js';
9
+ import '../BaseDoc-BT18xPxU.js';
10
10
  import '../client/PatchesStore.js';
@@ -11,7 +11,7 @@ import '../types.js';
11
11
  import '../json-patch/JSONPatch.js';
12
12
  import '@dabble/delta';
13
13
  import '../client/ClientAlgorithm.js';
14
- import '../BaseDoc-CD5wZQMm.js';
14
+ import '../BaseDoc-BT18xPxU.js';
15
15
  import '../client/PatchesStore.js';
16
16
  import '../net/PatchesSync.js';
17
17
  import '../algorithms/ot/shared/changeBatching.js';
@@ -1,4 +1,4 @@
1
- import { Ref, ShallowRef } from 'vue';
1
+ import { ShallowRef, Ref } from 'vue';
2
2
  import { OpenDocOptions } from '../client/Patches.js';
3
3
  import 'easy-signal';
4
4
  import '../json-patch/types.js';
@@ -6,7 +6,7 @@ import '../types.js';
6
6
  import '../json-patch/JSONPatch.js';
7
7
  import '@dabble/delta';
8
8
  import '../client/ClientAlgorithm.js';
9
- import '../BaseDoc-CD5wZQMm.js';
9
+ import '../BaseDoc-BT18xPxU.js';
10
10
  import '../client/PatchesStore.js';
11
11
 
12
12
  /**
@@ -7,7 +7,7 @@ import '../types.js';
7
7
  import '../json-patch/JSONPatch.js';
8
8
  import '@dabble/delta';
9
9
  import '../client/ClientAlgorithm.js';
10
- import '../BaseDoc-CD5wZQMm.js';
10
+ import '../BaseDoc-BT18xPxU.js';
11
11
  import '../client/PatchesStore.js';
12
12
  import '../algorithms/ot/shared/changeBatching.js';
13
13
  import '../client/BranchClientStore.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.8.15",
3
+ "version": "0.8.17",
4
4
  "description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
5
5
  "author": "Jacob Wright <jacwright@gmail.com>",
6
6
  "bugs": {