@syncular/tauri 0.49.2 → 0.51.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.ts CHANGED
@@ -28,7 +28,7 @@ import type { ClientSnapshotMethods, PromiseMethods } from '@syncular/client';
28
28
  * `invoke`/`listen` either from its ESM entry points, from the ambient
29
29
  * `window.__TAURI__`, or via injected doubles (tests).
30
30
  */
31
- import type { AuthorityReadPolicy, ClientChangeListener, ClientDiagnosticsListener, ClientDiagnosticsRequest, ClientDiagnosticsSnapshot, CommitOutcome, CommitOutcomeQuery, ConflictRecord, EncryptionKeyringConfig, InvalidationListener, LocalDataPurgeInput, LocalDataPurgeResult, LocalDataRebootstrapInput, LocalDataRebootstrapResult, MutationInput, PresencePeer, PreviousVersionAudit, PreviousVersionReadSpec, PreviousVersionSnapshot, QueryReadSpec, QuerySnapshot, RejectionRecord, ResolveCommitOutcomeInput, SecurityLifecycle, SnapshotRead, SnapshotReadRequest, SqlRow, SqlValue, SyncClientConfig, SyncStatusSnapshot, WindowBase, WindowState } from '@syncular/client';
31
+ import type { AuthorityReadPolicy, ClientChangeListener, ClientDiagnosticsListener, ClientDiagnosticsRequest, ClientDiagnosticsSnapshot, CommitOutcome, CommitOutcomeQuery, CurrentBaseProof, ConflictRecord, EncryptionKeyringConfig, InvalidationListener, LocalDataPurgeInput, LocalDataPurgeResult, LocalDataRebootstrapInput, LocalDataRebootstrapResult, MutationInput, PresencePeer, PreviousVersionAudit, PreviousVersionReadSpec, PreviousVersionSnapshot, QueryReadSpec, QuerySnapshot, RejectionRecord, ResolveCommitOutcomeInput, SecurityLifecycle, SnapshotRead, SnapshotReadRequest, SqlRow, SqlValue, SyncClientConfig, SyncStatusSnapshot, WindowBase, WindowState } from '@syncular/client';
32
32
  /** One event pushed on `syncular://event` (the derived client-observable set). */
33
33
  interface SyncularEvent {
34
34
  readonly type: string;
@@ -247,6 +247,7 @@ export declare class TauriSyncClient implements PromiseMethods<ClientSnapshotMet
247
247
  /** Roll back an attach that did not complete and return to `local`. */
248
248
  abandonLocalAuthorityAttach(): Promise<void>;
249
249
  syncUntilIdle(maxRounds?: number): Promise<unknown>;
250
+ proveCurrentBase(outcome: Pick<CommitOutcome, 'clientCommitId' | 'sequence'>, maxRounds?: number): Promise<CurrentBaseProof>;
250
251
  conflicts(): Promise<readonly ConflictRecord[]>;
251
252
  rejections(): Promise<readonly RejectionRecord[]>;
252
253
  commitOutcome(clientCommitId: string): Promise<CommitOutcome | undefined>;
package/dist/index.js CHANGED
@@ -122,6 +122,21 @@ function decodeOutcomeRow(row) {
122
122
  }
123
123
  return out;
124
124
  }
125
+ function decodeRetainedRows(rows) {
126
+ return rows.map((row) => ({
127
+ ...row,
128
+ localRow: row.localRow === null ? null : decodeOutcomeRow(row.localRow),
129
+ serverRow: row.serverRow === null ? null : decodeOutcomeRow(row.serverRow),
130
+ ...(row.uniqueConflicts !== undefined
131
+ ? {
132
+ uniqueConflicts: row.uniqueConflicts.map((conflict) => ({
133
+ ...conflict,
134
+ serverRow: decodeOutcomeRow(conflict.serverRow),
135
+ })),
136
+ }
137
+ : {}),
138
+ }));
139
+ }
125
140
  /** Decode the row images a native `CommitOutcome` carries: conflict server
126
141
  * rows and retained-row images. */
127
142
  function decodeCommitOutcome(outcome) {
@@ -138,19 +153,7 @@ function decodeCommitOutcome(outcome) {
138
153
  : result),
139
154
  ...(outcome.retainedRows !== undefined
140
155
  ? {
141
- retainedRows: outcome.retainedRows.map((row) => ({
142
- ...row,
143
- localRow: row.localRow === null ? null : decodeOutcomeRow(row.localRow),
144
- serverRow: row.serverRow === null ? null : decodeOutcomeRow(row.serverRow),
145
- ...(row.uniqueConflicts !== undefined
146
- ? {
147
- uniqueConflicts: row.uniqueConflicts.map((conflict) => ({
148
- ...conflict,
149
- serverRow: decodeOutcomeRow(conflict.serverRow),
150
- })),
151
- }
152
- : {}),
153
- })),
156
+ retainedRows: decodeRetainedRows(outcome.retainedRows),
154
157
  }
155
158
  : {}),
156
159
  };
@@ -724,6 +727,21 @@ export class TauriSyncClient {
724
727
  ...(maxRounds !== undefined ? { maxRounds } : {}),
725
728
  });
726
729
  }
730
+ async proveCurrentBase(outcome, maxRounds) {
731
+ if (maxRounds !== undefined &&
732
+ (!Number.isInteger(maxRounds) || maxRounds < 1 || maxRounds > 0xffffffff))
733
+ throw new TauriSyncError('sync.invalid_request', 'maxRounds must be a positive integer');
734
+ const proof = (await this.#command('proveCurrentBase', {
735
+ outcome: {
736
+ clientCommitId: outcome.clientCommitId,
737
+ sequence: outcome.sequence,
738
+ },
739
+ ...(maxRounds !== undefined ? { maxRounds } : {}),
740
+ }));
741
+ return proof.proven
742
+ ? { proven: true, rows: decodeRetainedRows(proof.rows) }
743
+ : proof;
744
+ }
727
745
  async conflicts() {
728
746
  const result = (await this.#command('conflicts', {}));
729
747
  return result.conflicts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/tauri",
3
- "version": "0.49.2",
3
+ "version": "0.51.0",
4
4
  "description": "Tauri integration for the Syncular client",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -56,13 +56,13 @@
56
56
  "test": "bun test"
57
57
  },
58
58
  "dependencies": {
59
- "@syncular/client": "0.49.2"
59
+ "@syncular/client": "0.51.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@tauri-apps/api": ">=2.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@syncular/react": "0.49.2",
66
- "@syncular/server": "0.49.2"
65
+ "@syncular/react": "0.51.0",
66
+ "@syncular/server": "0.51.0"
67
67
  }
68
68
  }
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ import type {
42
42
  ClientDiagnosticsSnapshot,
43
43
  CommitOutcome,
44
44
  CommitOutcomeQuery,
45
+ CurrentBaseProof,
45
46
  ConflictRecord,
46
47
  EncryptionKeyringConfig,
47
48
  InvalidationEvent,
@@ -59,6 +60,7 @@ import type {
59
60
  QuerySnapshot,
60
61
  RejectionRecord,
61
62
  ResolveCommitOutcomeInput,
63
+ RetainedCommitRow,
62
64
  SecurityLifecycle,
63
65
  SnapshotRead,
64
66
  SnapshotReadRequest,
@@ -319,6 +321,24 @@ function decodeOutcomeRow(
319
321
  return out;
320
322
  }
321
323
 
324
+ function decodeRetainedRows(
325
+ rows: readonly RetainedCommitRow[],
326
+ ): RetainedCommitRow[] {
327
+ return rows.map((row) => ({
328
+ ...row,
329
+ localRow: row.localRow === null ? null : decodeOutcomeRow(row.localRow),
330
+ serverRow: row.serverRow === null ? null : decodeOutcomeRow(row.serverRow),
331
+ ...(row.uniqueConflicts !== undefined
332
+ ? {
333
+ uniqueConflicts: row.uniqueConflicts.map((conflict) => ({
334
+ ...conflict,
335
+ serverRow: decodeOutcomeRow(conflict.serverRow),
336
+ })),
337
+ }
338
+ : {}),
339
+ }));
340
+ }
341
+
322
342
  /** Decode the row images a native `CommitOutcome` carries: conflict server
323
343
  * rows and retained-row images. */
324
344
  function decodeCommitOutcome(outcome: CommitOutcome): CommitOutcome {
@@ -337,21 +357,7 @@ function decodeCommitOutcome(outcome: CommitOutcome): CommitOutcome {
337
357
  ),
338
358
  ...(outcome.retainedRows !== undefined
339
359
  ? {
340
- retainedRows: outcome.retainedRows.map((row) => ({
341
- ...row,
342
- localRow:
343
- row.localRow === null ? null : decodeOutcomeRow(row.localRow),
344
- serverRow:
345
- row.serverRow === null ? null : decodeOutcomeRow(row.serverRow),
346
- ...(row.uniqueConflicts !== undefined
347
- ? {
348
- uniqueConflicts: row.uniqueConflicts.map((conflict) => ({
349
- ...conflict,
350
- serverRow: decodeOutcomeRow(conflict.serverRow),
351
- })),
352
- }
353
- : {}),
354
- })),
360
+ retainedRows: decodeRetainedRows(outcome.retainedRows),
355
361
  }
356
362
  : {}),
357
363
  };
@@ -1150,6 +1156,30 @@ export class TauriSyncClient implements PromiseMethods<ClientSnapshotMethods> {
1150
1156
  });
1151
1157
  }
1152
1158
 
1159
+ async proveCurrentBase(
1160
+ outcome: Pick<CommitOutcome, 'clientCommitId' | 'sequence'>,
1161
+ maxRounds?: number,
1162
+ ): Promise<CurrentBaseProof> {
1163
+ if (
1164
+ maxRounds !== undefined &&
1165
+ (!Number.isInteger(maxRounds) || maxRounds < 1 || maxRounds > 0xffffffff)
1166
+ )
1167
+ throw new TauriSyncError(
1168
+ 'sync.invalid_request',
1169
+ 'maxRounds must be a positive integer',
1170
+ );
1171
+ const proof = (await this.#command('proveCurrentBase', {
1172
+ outcome: {
1173
+ clientCommitId: outcome.clientCommitId,
1174
+ sequence: outcome.sequence,
1175
+ },
1176
+ ...(maxRounds !== undefined ? { maxRounds } : {}),
1177
+ })) as CurrentBaseProof;
1178
+ return proof.proven
1179
+ ? { proven: true, rows: decodeRetainedRows(proof.rows) }
1180
+ : proof;
1181
+ }
1182
+
1153
1183
  async conflicts(): Promise<readonly ConflictRecord[]> {
1154
1184
  const result = (await this.#command('conflicts', {})) as {
1155
1185
  conflicts: ConflictRecord[];