@dabble/patches 0.7.17 → 0.7.18

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.
@@ -81,8 +81,6 @@ async function commitChanges(store, docId, changes, sessionTimeoutMillis, option
81
81
  baseRev,
82
82
  batchId,
83
83
  origin,
84
- true,
85
- // isOffline
86
84
  maxStorageBytes
87
85
  );
88
86
  if (canFastForward) {
@@ -7,15 +7,19 @@ import '@dabble/delta';
7
7
  /**
8
8
  * Handles offline/large batch versioning logic for multi-batch uploads.
9
9
  * Groups changes into sessions, merges with previous batch if needed, and creates/extends versions.
10
+ *
11
+ * Each session's `isOffline` metadata is determined per-session by comparing `committedAt` and
12
+ * `createdAt` on the first change — if the gap exceeds `sessionTimeoutMillis`, the session is
13
+ * marked offline.
14
+ *
10
15
  * @param docId Document ID
11
16
  * @param changes The incoming changes (all with the same batchId)
12
17
  * @param baseRev The base revision for the batch
13
18
  * @param batchId The batch identifier
14
19
  * @param origin The origin to use for created versions (default: 'offline-branch')
15
- * @param isOffline Whether these changes were created offline (metadata flag)
16
20
  * @param maxStorageBytes If set, break collapsed changes that exceed this size
17
21
  * @returns The changes (collapsed into one if divergent, unchanged if fast-forward)
18
22
  */
19
- declare function handleOfflineSessionsAndBatches(store: OTStoreBackend, sessionTimeoutMillis: number, docId: string, changes: Change[], baseRev: number, batchId?: string, origin?: 'main' | 'offline-branch', isOffline?: boolean, maxStorageBytes?: number): Promise<Change[]>;
23
+ declare function handleOfflineSessionsAndBatches(store: OTStoreBackend, sessionTimeoutMillis: number, docId: string, changes: Change[], baseRev: number, batchId?: string, origin?: 'main' | 'offline-branch', maxStorageBytes?: number): Promise<Change[]>;
20
24
 
21
25
  export { handleOfflineSessionsAndBatches };
@@ -3,7 +3,7 @@ import { createVersionMetadata } from "../../../data/version.js";
3
3
  import { applyChanges } from "../shared/applyChanges.js";
4
4
  import { breakChanges } from "../shared/changeBatching.js";
5
5
  import { getStateAtRevision } from "./getStateAtRevision.js";
6
- async function handleOfflineSessionsAndBatches(store, sessionTimeoutMillis, docId, changes, baseRev, batchId, origin = "offline-branch", isOffline = true, maxStorageBytes) {
6
+ async function handleOfflineSessionsAndBatches(store, sessionTimeoutMillis, docId, changes, baseRev, batchId, origin = "offline-branch", maxStorageBytes) {
7
7
  const [lastVersion] = await store.listVersions(docId, {
8
8
  groupId: batchId,
9
9
  reverse: true,
@@ -35,11 +35,12 @@ async function handleOfflineSessionsAndBatches(store, sessionTimeoutMillis, docI
35
35
  parentId = lastVersion.parentId;
36
36
  } else {
37
37
  offlineBaseState = applyChanges(offlineBaseState, sessionChanges);
38
+ const isOffline = sessionChanges[0].committedAt - sessionChanges[0].createdAt > sessionTimeoutMillis;
38
39
  const sessionMetadata = createVersionMetadata({
39
40
  parentId,
40
41
  groupId: batchId,
41
42
  origin,
42
- isOffline,
43
+ ...isOffline ? { isOffline } : {},
43
44
  startedAt: sessionChanges[0].createdAt,
44
45
  endedAt: sessionChanges[sessionChanges.length - 1].createdAt,
45
46
  endRev: sessionChanges[sessionChanges.length - 1].rev,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.7.17",
3
+ "version": "0.7.18",
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": {