@dabble/patches 0.5.13 → 0.5.15

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.
@@ -24,9 +24,7 @@ const text = {
24
24
  doc = new Delta().insert("\n");
25
25
  }
26
26
  doc = doc.compose(delta);
27
- if (hasInvalidOps(doc)) {
28
- return "Invalid text delta provided for this text document";
29
- }
27
+ doc = fixBadDeltaDoc(doc);
30
28
  return replace.apply(state, path, doc);
31
29
  },
32
30
  transform(state, thisOp, otherOps) {
@@ -49,8 +47,25 @@ const text = {
49
47
  return new Delta(delta1).compose(new Delta(delta2));
50
48
  }
51
49
  };
52
- function hasInvalidOps(doc) {
53
- return doc.ops.some((op) => typeof op.insert !== "string" && (typeof op.insert !== "object" || op.insert === null));
50
+ function fixBadDeltaDoc(delta) {
51
+ const ops = delta.ops;
52
+ while (ops.length && ops[ops.length - 1].insert === void 0) {
53
+ ops.pop();
54
+ }
55
+ if (ops.every((op) => op.insert !== void 0)) {
56
+ return delta;
57
+ }
58
+ const newDelta = new Delta();
59
+ for (const op of ops) {
60
+ if (op.insert !== void 0) {
61
+ newDelta.push(op);
62
+ } else if (op.retain) {
63
+ const insertOp = { insert: "".padStart(op.retain) };
64
+ if (op.attributes) insertOp.attributes = op.attributes;
65
+ newDelta.push(insertOp);
66
+ }
67
+ }
68
+ return newDelta;
54
69
  }
55
70
  export {
56
71
  text
@@ -1,5 +1,5 @@
1
1
  import { Signal } from '../event-signal.js';
2
- import { Change, PatchesState, ChangeInput, CommitChangesOptions, EditableVersionMetadata, ListVersionsOptions, VersionMetadata, PatchesSnapshot } from '../types.js';
2
+ import { Change, PatchesState, ChangeInput, CommitChangesOptions, DeleteDocOptions, EditableVersionMetadata, ListVersionsOptions, VersionMetadata, PatchesSnapshot } from '../types.js';
3
3
  import { JSONRPCClient } from './protocol/JSONRPCClient.js';
4
4
  import { PatchesAPI, ClientTransport } from './protocol/types.js';
5
5
  import '../json-patch/JSONPatch.js';
@@ -61,9 +61,10 @@ declare class PatchesClient implements PatchesAPI {
61
61
  /**
62
62
  * Deletes a document on the server.
63
63
  * @param docId - The ID of the document to delete.
64
+ * @param options - Optional deletion settings (e.g., skipTombstone).
64
65
  * @returns A promise resolving when the deletion is confirmed.
65
66
  */
66
- deleteDoc(docId: string): Promise<void>;
67
+ deleteDoc(docId: string, options?: DeleteDocOptions): Promise<void>;
67
68
  /**
68
69
  * Creates a named version snapshot of a document's current state on the server.
69
70
  * @param docId - The ID of the document.
@@ -74,10 +74,11 @@ class PatchesClient {
74
74
  /**
75
75
  * Deletes a document on the server.
76
76
  * @param docId - The ID of the document to delete.
77
+ * @param options - Optional deletion settings (e.g., skipTombstone).
77
78
  * @returns A promise resolving when the deletion is confirmed.
78
79
  */
79
- async deleteDoc(docId) {
80
- return this.rpc.call("deleteDoc", { docId });
80
+ async deleteDoc(docId, options) {
81
+ return this.rpc.call("deleteDoc", { docId, options });
81
82
  }
82
83
  // === Version Operations ===
83
84
  /**
@@ -1,4 +1,4 @@
1
- import { PatchesState, Change, CommitChangesOptions, ListVersionsOptions, VersionMetadata, EditableVersionMetadata, ListChangesOptions, Branch } from '../../types.js';
1
+ import { PatchesState, Change, CommitChangesOptions, DeleteDocOptions, ListVersionsOptions, VersionMetadata, EditableVersionMetadata, ListChangesOptions, Branch } from '../../types.js';
2
2
  import { PatchesBranchManager } from '../../server/PatchesBranchManager.js';
3
3
  import { PatchesHistoryManager } from '../../server/PatchesHistoryManager.js';
4
4
  import { PatchesServer } from '../../server/PatchesServer.js';
@@ -78,9 +78,11 @@ declare class RPCServer {
78
78
  * @param connectionId - The ID of the connection making the request
79
79
  * @param params - The deletion parameters
80
80
  * @param params.docId - The ID of the document to delete
81
+ * @param params.options - Optional deletion settings (e.g., skipTombstone)
81
82
  */
82
83
  deleteDoc(params: {
83
84
  docId: string;
85
+ options?: DeleteDocOptions;
84
86
  }, ctx?: AuthContext): Promise<void>;
85
87
  /**
86
88
  * Removes the tombstone for a deleted document, allowing it to be recreated.
@@ -90,11 +90,12 @@ class RPCServer {
90
90
  * @param connectionId - The ID of the connection making the request
91
91
  * @param params - The deletion parameters
92
92
  * @param params.docId - The ID of the document to delete
93
+ * @param params.options - Optional deletion settings (e.g., skipTombstone)
93
94
  */
94
95
  async deleteDoc(params, ctx) {
95
- const { docId } = params;
96
+ const { docId, options } = params;
96
97
  await this.assertWrite(ctx, docId, "deleteDoc", params);
97
- await this.patches.deleteDoc(docId, ctx?.clientId);
98
+ await this.patches.deleteDoc(docId, ctx?.clientId, options);
98
99
  }
99
100
  /**
100
101
  * Removes the tombstone for a deleted document, allowing it to be recreated.
@@ -3,7 +3,7 @@ export { PatchesBranchManager } from './PatchesBranchManager.js';
3
3
  export { PatchesHistoryManager } from './PatchesHistoryManager.js';
4
4
  export { PatchesServer, PatchesServerOptions } from './PatchesServer.js';
5
5
  export { BranchingStoreBackend, PatchesStoreBackend } from './types.js';
6
- export { CommitChangesOptions } from '../types.js';
6
+ export { CommitChangesOptions, DeleteDocOptions } from '../types.js';
7
7
  import '../compression/index.js';
8
8
  import '../algorithms/shared/lz.js';
9
9
  import '../json-patch/types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
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": {